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
12
+ from matplotlib import default_test_modules
11
13
from matplotlib .testing .decorators import ImageComparisonTest
12
14
13
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
+ """Check if test is blacklisted and should be ignored"""
28
+ head , tests_dir = os .path .split (path .dirname )
29
+ if tests_dir != 'tests' :
30
+ return True
31
+ head , top_module = os .path .split (head )
32
+ return path .purebasename in IGNORED_TESTS .get (top_module , [])
33
+
34
+
35
+ def whitelist_check (path ):
36
+ """Check if test is not whitelisted and should be ignored"""
37
+ left = path .dirname
38
+ last_left = None
39
+ module_path = path .purebasename
40
+ while len (left ) and left != last_left :
41
+ last_left = left
42
+ left , tail = os .path .split (left )
43
+ module_path = '.' .join ([tail , module_path ])
44
+ if module_path in default_test_modules :
45
+ return False
46
+ return True
47
+
48
+
49
+ COLLECT_FILTERS = {
50
+ 'none' : lambda _ : False ,
51
+ 'blacklist' : blacklist_check ,
52
+ 'whitelist' : whitelist_check ,
53
+ }
54
+
55
+
14
56
def is_nose_class (cls ):
57
+ """Check if supplied class looks like Nose testcase"""
15
58
return any (name in ['setUp' , 'tearDown' ]
16
59
for name , _ in inspect .getmembers (cls ))
17
60
18
61
62
+ def pytest_addoption (parser ):
63
+ group = parser .getgroup ("matplotlib" , "matplotlib custom options" )
64
+
65
+ group .addoption ('--collect-filter' , action = 'store' ,
66
+ choices = COLLECT_FILTERS , default = 'whitelist' ,
67
+ help = 'filter tests during collection phase' )
68
+
69
+
19
70
def pytest_configure (config ):
20
71
matplotlib ._called_from_pytest = True
21
72
@@ -24,6 +75,12 @@ def pytest_unconfigure(config):
24
75
matplotlib ._called_from_pytest = False
25
76
26
77
78
+ def pytest_ignore_collect (path , config ):
79
+ if path .ext == '.py' :
80
+ collect_filter = config .getoption ('--collect-filter' )
81
+ return COLLECT_FILTERS [collect_filter ](path )
82
+
83
+
27
84
def pytest_pycollect_makeitem (collector , name , obj ):
28
85
if inspect .isclass (obj ):
29
86
if issubclass (obj , ImageComparisonTest ):
0 commit comments