8000 Implemented test filtering for pytest · matplotlib/matplotlib@c5ce784 · GitHub
[go: up one dir, main page]

Skip to content

Commit c5ce784

Browse files
committed
Implemented test filtering for pytest
1 parent 30caf00 commit c5ce784

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

conftest.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,60 @@
22
unicode_literals)
33

44
import inspect
5+
import os
56
import pytest
67
import unittest
78

89
import matplotlib
910
matplotlib.use('agg')
1011

11-
from matplotlib.testing.decorators import ImageComparisonTest
1212
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+
}
1346

1447

1548
def 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+
2059
def 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+
2873
def pytest_pycollect_makeitem(collector, name, obj):
2974
if inspect.isclass(obj):
3075
if issubclass(obj, ImageComparisonTest):

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
norecursedirs = .git build ci dist extern release tools unit

0 commit comments

Comments
 (0)
0