From 0717e443fdacb94cb0c590431f0b222fd715bffe Mon Sep 17 00:00:00 2001 From: Kurt Grandis Date: Thu, 25 Jun 2015 01:41:05 -0400 Subject: [PATCH] futurize code also add ability to fetch a method's class depending on whether the system is py2 or py3 --- nose_exclude.py | 12 ++++++++++-- test_dirs/unittest/tests.py | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nose_exclude.py b/nose_exclude.py index 72f8316..ab96c6b 100644 --- a/nose_exclude.py +++ b/nose_exclude.py @@ -1,9 +1,17 @@ +from __future__ import unicode_literals + +import sys import os import logging from nose.plugins import Plugin log = logging.getLogger('nose.plugins.nose_exclude') +if sys.version_info > (3,): + get_method_class = lambda x: x.__self__.__class__ +else: + get_method_class = lambda x: x.im_class + class NoseExclude(Plugin): @@ -108,7 +116,7 @@ class NoseExclude(Plugin): if abs_d: self.exclude_dirs[abs_d] = True - exclude_str = "excluding dirs: %s" % ",".join(self.exclude_dirs.keys()) + exclude_str = "excluding dirs: %s" % ",".join(list(self.exclude_dirs.keys())) log.debug(exclude_str) def wantDirectory(self, dirname): @@ -140,7 +148,7 @@ class NoseExclude(Plugin): def wantMethod(self, meth): """Filter out tests based on ..""" try: - cls = meth.im_class # Don't test static methods + cls = get_method_class(meth) except AttributeError: return False diff --git a/test_dirs/unittest/tests.py b/test_dirs/unittest/tests.py index ead4495..be5db37 100644 --- a/test_dirs/unittest/tests.py +++ b/test_dirs/unittest/tests.py @@ -1,5 +1,6 @@ import unittest + class UnitTests(unittest.TestCase): def test_a(self): assert True @@ -7,5 +8,6 @@ class UnitTests(unittest.TestCase): def test_b(self): assert True + def test_c(): assert True