3
3
4
4
import inspect
5
5
import pytest
6
+ import unittest
6
7
7
8
import matplotlib
8
9
matplotlib .use ('agg' )
9
10
10
11
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 ))
11
18
12
19
13
20
def pytest_configure (config ):
@@ -25,3 +32,20 @@ def pytest_pycollect_makeitem(collector, name, obj):
25
32
# instead of function and this confuses pytest because it crawls
26
33
# original names and sees 'test_*', but not 'Test*' in that case
27
34
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