Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cd914d

Browse files
committed
Move most of pytest's conf to conftest.py.
pytest.ini is not found if running the test suite from anywhere but a source checkout root. For example, it is not found if running `matplotlib.test()` from an installed Matplotlib (that includes test data). mplcairo's test suite also relies on being able to run the Matplotlib test suite from not-the-source-tree (via `pytest --pyargs matplotlib`). This is particularly problematic now that pytest requires markers to be explicitly declared, and emits a warning when they are not. Instead, declare most relevant options in pytest_configure(). (Note that this actually only helps mplcairo when used in conjunction of pytest>=5.0 due to pytest issue 5078, but the patch doesn't bump the pytest version requirement for matplotlib.) See also pytest issue 4039.
1 parent 666d3d0 commit 2cd914d

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

lib/matplotlib/testing/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55

66

77
def pytest_configure(config):
8+
# config is initialized here rather than in pytest.ini so that `pytest
9+
# --pyargs matplotlib` (which would not find pytest.ini) works. The only
10+
# entries in pytest.ini set minversion (which is checked earlier) and
11+
# testpaths/python_files, as they are required to properly find the tests.
12+
for key, value in [
13+
("markers", "flaky: (Provided by pytest-rerunfailures.)"),
14+
("markers", "timeout: (Provided by pytest-timeout.)"),
15+
("markers", "backend: Set alternate Matplotlib backend temporarily."),
16+
("markers", "style: Set alternate Matplotlib style temporarily."),
17+
("markers", "baseline_images: Compare output against references."),
18+
("markers", "pytz: Tests that require pytz to be installed."),
19+
("filterwarnings", "error"),
20+
]:
21+
config.addinivalue_line(key, value)
22+
823
matplotlib.use('agg', force=True)
924
matplotlib._called_from_pytest = True
1025
matplotlib._init_tests()

pytest.ini

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1+
# Additional configuration is in matplotlib/testing/conftest.py.
12
[pytest]
23
minversion = 3.6
34

45
testpaths = lib
56
python_files = test_*.py
6-
7-
markers =
8-
flaky: (Provided by pytest-rerunfailures.)
9-
timeout: (Provided by pytest-timeout.)
10-
backend: Set alternate Matplotlib backend temporarily.
11-
style: Set alternate Matplotlib style temporarily.
12-
baseline_images: Compare output against a known reference.
13-
pytz: Tests that require pytz to be installed.
14-
15-
filterwarnings =
16-
error

0 commit comments

Comments
 (0)