22 unicode_literals )
33
44import inspect
5+ import os
56import pytest
67import unittest
78
89import matplotlib
910matplotlib .use ('agg' )
1011
11- from matplotlib .testing .decorators import ImageComparisonTest
1212from 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+ }
1346
1447
1548def is_nose_class (cls ):
1649 return any (name in ['setUp' , 'tearDown' ]
1750 for name , _ in inspect .getmembers (cls ))
1851
1952
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+
2059def pytest_configure (config ):
2160 matplotlib ._called_from_pytest = True
2261
@@ -25,6 +64,12 @@ def pytest_unconfigure(config):
2564 matplotlib ._called_from_pytest = False
2665
2766
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+
2873def pytest_pycollect_makeitem (collector , name , obj ):
2974 if inspect .isclass (obj ):
3075 if issubclass (obj , ImageComparisonTest ):
0 commit comments