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