Skip to content

Commit 74d8299

Browse files
committed
Decorators now wrap testcls.setup/teardown for pytest/nose test classes
1 parent 892b72f commit 74d8299

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

case/utils.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,39 +60,38 @@ def is_unittest_testcase(cls):
6060
except AttributeError:
6161
pass # py.test uses old style classes
6262
else:
63-
for parent in mro():
64-
if issubclass(parent, unittest.TestCase):
65-
return True
63+
return issubclass(cls, unittest.TestCase)
6664

6765

6866
def augment_setup(orig_setup, context, pargs, pkwargs):
69-
def around_setup_method(*args, **kwargs):
67+
def around_setup_method(self, *args, **kwargs):
7068
try:
71-
contexts = args[0].__rb3dc_contexts__
69+
contexts = self.__rb3dc_contexts__
7270
except AttributeError:
73-
contexts = args[0].__rb3dc_contexts = []
71+
contexts = self.__rb3dc_contexts = []
7472
p = context(*pargs, **pkwargs)
7573
p.__enter__()
7674
contexts.append(p)
7775
if orig_setup:
78-
return orig_setup(*args, **kwargs)
76+
print('CALLING ORIG SETUP: %r %r %r' % (orig_setup, args, kwargs))
77+
return orig_setup(self, *args, **kwargs)
7978
if orig_setup:
8079
around_setup_method = wraps(orig_setup)(around_setup_method)
8180
around_setup_method.__wrapped__ = orig_setup
8281
return around_setup_method
8382

8483

8584
def augment_teardown(orig_teardown, context, pargs, pkwargs):
86-
def around_teardown(*args, **kwargs):
85+
def around_teardown(self, *args, **kwargs):
8786
try:
88-
contexts = args[0].__rb3dc_contexts__
87+
contexts = self.__rb3dc_contexts__
8988
except AttributeError:
9089
pass
9190
else:
9291
for context in contexts:
9392
context.__exit__(*sys.exc_info())
9493
if orig_teardown:
95-
orig_teardown(*args, **kwargs)
94+
orig_teardown(self, *args, **kwargs)
9695
if orig_teardown:
9796
around_teardown = wraps(orig_teardown)(around_teardown)
9897
around_teardown.__wrapped__ = orig_teardown
@@ -116,8 +115,8 @@ def decorator(cls):
116115
cls.tearDown = augment_teardown(
117116
orig_teardown, context, pargs, pkwargs)
118117
else: # py.test
119-
orig_setup = getattr(cls, 'setup_method', None)
120-
orig_teardown = getattr(cls, 'teardown_method', None)
118+
orig_setup = getattr(cls, 'setup', None)
119+
orig_teardown = getattr(cls, 'teardown', None)
121120
cls.setup_method = augment_setup(
122121
orig_setup, context, pargs, pkwargs)
123122
cls.teardown_method = augment_teardown(

0 commit comments

Comments
 (0)