|
9 | 9 | import matplotlib |
10 | 10 | matplotlib.use('agg') |
11 | 11 |
|
12 | | -from matplotlib import default_test_modules |
13 | | - |
14 | | - |
15 | | -IGNORED_TESTS = { |
16 | | - 'matplotlib': [], |
17 | | -} |
18 | | - |
19 | | - |
20 | | -def blacklist_check(path): |
21 | | - """Check if test is blacklisted and should be ignored""" |
22 | | - head, tests_dir = os.path.split(path.dirname) |
23 | | - if tests_dir != 'tests': |
24 | | - return True |
25 | | - head, top_module = os.path.split(head) |
26 | | - return path.purebasename in IGNORED_TESTS.get(top_module, []) |
27 | | - |
28 | | - |
29 | | -def whitelist_check(path): |
30 | | - """Check if test is not whitelisted and should be ignored""" |
31 | | - left = path.dirname |
32 | | - last_left = None |
33 | | - module_path = path.purebasename |
34 | | - while len(left) and left != last_left: |
35 | | - last_left = left |
36 | | - left, tail = os.path.split(left) |
37 | | - module_path = '.'.join([tail, module_path]) |
38 | | - if module_path in default_test_modules: |
39 | | - return False |
40 | | - return True |
41 | | - |
42 | | - |
43 | | -COLLECT_FILTERS = { |
44 | | - 'none': lambda _: False, |
45 | | - 'blacklist': blacklist_check, |
46 | | - 'whitelist': whitelist_check, |
47 | | -} |
48 | | - |
49 | | - |
50 | | -def pytest_addoption(parser): |
51 | | - group = parser.getgroup("matplotlib", "matplotlib custom options") |
52 | | - |
53 | | - group.addoption('--collect-filter', action='store', |
54 | | - choices=COLLECT_FILTERS, default='blacklist', |
55 | | - help='filter tests during collection phase') |
56 | | - |
57 | | - group.addoption('--no-pep8', action='store_true', |
58 | | - help='skip PEP8 compliance tests') |
59 | | - |
60 | 12 |
|
61 | 13 | def pytest_configure(config): |
62 | 14 | matplotlib._called_from_pytest = True |
63 | 15 | matplotlib._init_tests() |
64 | 16 |
|
65 | | - if config.getoption('--no-pep8'): |
66 | | - IGNORED_TESTS['matplotlib'] += 'test_coding_standards' |
67 | | - |
68 | 17 |
|
69 | 18 | def pytest_unconfigure(config): |
70 | 19 | matplotlib._called_from_pytest = False |
71 | | - |
72 | | - |
73 | | -def pytest_ignore_collect(path, config): |
74 | | - if path.ext == '.py': |
75 | | - collect_filter = config.getoption('--collect-filter') |
76 | | - return COLLECT_FILTERS[collect_filter](path) |
0 commit comments