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
39from argparse import ArgumentParser
410import 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
7267def 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
114116if __name__ == "__main__" :
0 commit comments