2
2
unicode_literals )
3
3
4
4
import inspect
5
+ import os
5
6
import pytest
6
7
import unittest
7
8
8
9
import matplotlib
9
10
matplotlib .use ('agg' )
10
11
11
- from matplotlib .testing .decorators import ImageComparisonTest
12
12
from matplotlib import default_test_modules
13
+ from matplotlib .testing .decorators import ImageComparisonTest
14
+
15
+
16
+ IGNORED_TESTS = {
17
+ 'matplotlib' : [
18
+ 'test_sankey' ,
19
+ 'test_skew' ,
20
+ 'test_ttconv' ,
21
+ 'test_usetex' ,
22
+ ],
23
+ }
24
+
25
+
26
+ def blacklist_check (path ):
27
+ head , tests_dir = os .path .split (path .dirname )
28
+ if tests_dir != 'tests' :
29
+ return True
30
+ head , top_module = os .path .split (head )
31
+ return path .purebasename in IGNORED_TESTS .get (top_module , [])
32
+
33
+
34
+ def whitelist_check (path ):
35
+ head , tests_dir = os .path .split (path .dirname )
36
+ head , top_module = os .path .split (head )
37
+ test_name = '.' .join ([top_module , tests_dir , path .purebasename ])
38
+ return test_name not in default_test_modules
39
+
40
+
41
+ COLLECT_FILTERS = {
42
+ 'none' : lambda _ : False ,
43
+ 'blacklist' : blacklist_check ,
44
+ 'whitelist' : whitelist_check ,
45
+ }
13
46
14
47
15
48
def is_nose_class (cls ):
16
49
return any (name in ['setUp' , 'tearDown' ]
17
50
for name , _ in inspect .getmembers (cls ))
18
51
19
52
53
+ def pytest_addoption (parser ):
54
+ parser .addoption ('--collect-filter' , action = 'store' ,
55
+ choices = COLLECT_FILTERS , default = 'whitelist' ,
56
+ help = 'filter tests during collection phase' )
57
+
58
+
20
59
def pytest_configure (config ):
21
60
matplotlib ._called_from_pytest = True
22
61
@@ -25,6 +64,12 @@ def pytest_unconfigure(config):
25
64
matplotlib ._called_from_pytest = False
26
65
27
66
67
+ def pytest_ignore_collect (path , config ):
68
+ if path .ext == '.py' :
69
+ collect_filter = config .getoption ('--collect-filter' )
70
+ return COLLECT_FILTERS [collect_filter ](path )
71
+
72
+
28
73
def pytest_pycollect_makeitem (collector , name , obj ):
29
74
if inspect .isclass (obj ):
30
75
if issubclass (obj , ImageComparisonTest ):
0 commit comments