Skip to content

Commit 7927eb2

Browse files
committed
Find Matplotlib tests suite using --pyargs.
The original patch was provided by QuLogic.
1 parent 6a51476 commit 7927eb2

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

README.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,11 @@ Keep in mind that conda-forge's cairo is (on my setup) ~2× slower than a
272272
Test suite
273273
==========
274274

275-
Run ``run-mpl-test-suite.py`` to run the Matplotlib test suite with
276-
the Agg backend patched by the mplcairo backend. Matplotlib *must* be
277-
editably-installed from a git checkout.
275+
Run ``run-mpl-test-suite.py`` to run the Matplotlib test suite with the
276+
Agg backend patched by the mplcairo backend. Note that Matplotlib must be
277+
installed with its test data, which is not the case when it is installed from
278+
conda or from most Linux distributions; instead, it should be installed from
279+
PyPI or from source.
278280

279281
Nearly all image comparison tests "fail" as the renderers are fundamentally
280282
different; currently, the intent is to manually check the diff images. Passing

run-mpl-test-suite.py

+30-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/usr/bin/env python
2+
"""
3+
Run the Matplotlib test suite, using the mplcairo backend to patch out
4+
Matplotlib's agg backend.
5+
6+
.. PYTEST_DONT_REWRITE
7+
"""
28

39
from argparse import ArgumentParser
410
import os
@@ -49,32 +55,24 @@ def compare_images(*args, **kwargs):
4955
import matplotlib.pyplot as plt
5056
plt.switch_backend("agg")
5157

52-
cwd = os.getcwd()
53-
try:
54-
matplotlib_srcdir = os.fsdecode(subprocess.check_output(
55-
["git", "rev-parse", "--show-toplevel"],
56-
cwd=Path(matplotlib.__file__).parent)[:-1])
57-
except CalledProcessError:
58-
sys.exit("This script must be run in an environment where Matplotlib "
59-
"is installed as an editable install.")
60-
61-
os.chdir(matplotlib_srcdir)
62-
rv = pytest.main(["-p", "__main__", *rest])
63-
os.chdir(cwd)
64-
result_images = Path(matplotlib_srcdir, "result_images")
65-
if result_images.exists():
66-
dest = Path(cwd, "result_images")
67-
shutil.rmtree(str(dest), ignore_errors=True)
68-
result_images.replace(dest)
69-
return rv
58+
return pytest.main([
59+
"-p", "__main__",
60+
# Don't get confused by our *own* conftest...
61+
"-p", "no:{}".format(Path(__file__).parent.resolve()
62+
/ "tests/conftest.py"),
63+
"--pyargs", "matplotlib",
64+
*rest])
7065

7166

7267
def pytest_collection_modifyitems(session, config, items):
68+
if len(items) == 0:
69+
pytest.exit("No tests found; Matplotlib was likely installed without "
70+
"test data.")
7371
excluded_modules = {
7472
"matplotlib.tests.test_compare_images",
7573
}
7674
excluded_nodeids = {
77-
"lib/matplotlib/tests/" + name for name in [
75+
"matplotlib/tests/" + name for name in [
7876
"test_agg.py::test_repeated_save_with_alpha",
7977
"test_artist.py::test_cull_markers",
8078
"test_backend_pdf.py::test_composite_image",
@@ -97,18 +95,22 @@ def pytest_collection_modifyitems(session, config, items):
9795
"test_simplification.py::test_throw_rendering_complexity_exceeded",
9896
]
9997
}
100-
filtered = []
98+
selected = []
99+
deselected = []
101100
for item in items:
102-
if item.module.__name__ in excluded_modules:
103-
pass
104-
elif item.nodeid in excluded_nodeids:
105-
excluded_nodeids -= {item.nodeid}
101+
if (item.module.__name__ in excluded_modules
102+
or item.nodeid in excluded_nodeids):
103+
deselected.append(item)
106104
else:
107-
filtered.append(item)
108-
if excluded_nodeids:
105+
selected.append(item)
106+
items[:] = selected
107+
config.hook.pytest_deselected(items=deselected)
108+
invalid_exclusions = (
109+
(excluded_modules - {item.module.__name__ for item in deselected})
110+
| (excluded_nodeids - {item.nodeid for item in deselected}))
111+
if invalid_exclusions:
109112
warnings.warn("Unused exclusions:\n {}"
110-
.format("\n ".join(sorted(excluded_nodeids))))
111-
items[:] = filtered
113+
.format("\n ".join(sorted(invalid_exclusions))))
112114

113115

114116
if __name__ == "__main__":

0 commit comments

Comments
 (0)