8000 Add support of nose setup/teardown to pytest collector · matplotlib/matplotlib@8b64294 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b64294

Browse files
committed
Add support of nose setup/teardown to pytest collector
1 parent bbaf7dc commit 8b64294

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33

44
import inspect
55
import pytest
6+
import unittest
67

78
import matplotlib
89
matplotlib.use('agg')
910

1011
from matplotlib.testing.decorators import ImageComparisonTest
12+
from matplotlib import default_test_modules
13+
14+
15+
def is_nose_class(cls):
16+
return any(name in ['setUp', 'tearDown']
17+
for name, _ in inspect.getmembers(cls))
1118

1219

1320
def pytest_configure(config):
@@ -25,3 +32,20 @@ def pytest_pycollect_makeitem(collector, name, obj):
2532
# instead of function and this confuses pytest because it crawls
2633
# original names and sees 'test_*', but not 'Test*' in that case
2734
return pytest.Class(name, parent=collector)
35+
36+
if is_nose_class(obj) and not issubclass(obj, unittest.TestCase):
37+
# Workaround unittest-like setup/teardown names in pure classes
38+
setup = getattr(obj, 'setUp', None)
39+
if setup is not None:
40+
obj.setup_method = lambda self, _: obj.setUp(self)
41+
tearDown = getattr(obj, 'tearDown', None)
42+
if tearDown is not None:
43+
obj.teardown_method = lambda self, _: obj.tearDown(self)
44+
setUpClass = getattr(obj, 'setUpClass', None)
45+
if setUpClass is not None:
46+
obj.setup_class = obj.setUpClass
47+
tearDownClass = getattr(obj, 'tearDownClass', None)
< 4E09 /code>48+
if tearDownClass is not None:
49+
obj.teardown_class = obj.tearDownClass
50+
51+
return pytest.Class(name, parent=collector)

0 commit comments

Comments
 (0)
0