10000 Merge pull request #27552 from QuLogic/pytest-importmode · matplotlib/matplotlib@8da0df9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8da0df9

Browse files
authored
Merge pull request #27552 from QuLogic/pytest-importmode
TST: Use importlib for importing in pytest
2 parents 101ffe8 + 88e6aeb commit 8da0df9

File tree

7 files changed

+37
-15
lines changed

7 files changed

+37
-15
lines changed

.github/workflows/cygwin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ jobs:
242242
shell: bash.exe -eo pipefail -o igncr "{0}"
243243
id: cygwin-run-pytest
244244
run: |
245-
xvfb-run python -mpytest -raR -n auto \
245+
xvfb-run pytest -raR -n auto \
246246
--maxfail=50 --timeout=300 --durations=25 \
247247
--cov-report=xml --cov=lib --log-level=DEBUG --color=yes
248248

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ jobs:
316316

317317
- name: Run pytest
318318
run: |
319-
python -mpytest -raR -n auto \
319+
pytest -raR -n auto \
320320
--maxfail=50 --timeout=300 --durations=25 \
321321
--cov-report=xml --cov=lib --log-level=DEBUG --color=yes
322322

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ stages:
225225
fi
226226
echo "##vso[task.setvariable variable=VS_COVERAGE_TOOL]$TOOL"
227227
fi
228-
PYTHONFAULTHANDLER=1 python -m pytest -raR -n 2 \
228+
PYTHONFAULTHANDLER=1 pytest -raR -n 2 \
229229
--maxfail=50 --timeout=300 --durations=25 \
230230
--junitxml=junit/test-results.xml --cov-report=xml --cov=lib ||
231231
[[ "$PYTHON_VERSION" = 'Pre' ]]

doc/api/prev_api_changes/api_changes_3.5.0/deprecations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ is thus deprecated as well.
353353
To test an installed copy, be sure to specify both ``matplotlib`` and
354354
``mpl_toolkits`` with ``--pyargs``::
355355

356-
python -m pytest --pyargs matplotlib.tests mpl_toolkits.tests
356+
pytest --pyargs matplotlib.tests mpl_toolkits.tests
357357

358358
See :ref:`testing` for more details.
359359

doc/api/prev_api_changes/api_changes_3.7.0/removals.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ is thus removed as well.
185185
To test an installed copy, be sure to specify both ``matplotlib`` and
186186
``mpl_toolkits`` with ``--pyargs``::
187187

188-
python -m pytest --pyargs matplotlib.tests mpl_toolkits.tests
188+
pytest --pyargs matplotlib.tests mpl_toolkits.tests
189189

190190
See :ref:`testing` for more details.
191191

doc/devel/testing.rst

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ Running the tests
3737

3838
In the root directory of your development repository run::
3939

40-
python -m pytest
40+
pytest
4141

4242

43-
pytest can be configured via a lot of `command-line parameters`_. Some
44-
particularly useful ones are:
43+
``pytest`` can be configured via many :external+pytest:doc:`command-line parameters
44+
<how-to/usage>`. Some particularly useful ones are:
4545

4646
============================= ===========
4747
``-v`` or ``--verbose`` Be more verbose
@@ -50,14 +50,32 @@ particularly useful ones are:
5050
``--capture=no`` or ``-s`` Do not capture stdout
5151
============================= ===========
5252

53-
To run a single test from the command line, you can provide a file path,
54-
optionally followed by the function separated by two colons, e.g., (tests do
55-
not need to be installed, but Matplotlib should be)::
53+
To run a single test from the command line, you can provide a file path, optionally
54+
followed by the function separated by two colons, e.g., (tests do not need to be
55+
installed, but Matplotlib should be)::
5656

5757
pytest lib/matplotlib/tests/test_simplification.py::test_clipping
5858

59+
If you want to use ``pytest`` as a module (via ``python -m pytest``), then you will need
60+
to avoid clashes between ``pytest``'s import mode and Python's search path:
5961

60-
.. _command-line parameters: http://doc.pytest.org/en/latest/usage.html
62+
- On more recent Python, you may :external+python:std:option:`disable "unsafe import
63+
paths" <-P>` (i.e., stop adding the current directory to the import path) with the
64+
``-P`` argument::
65+
66+
python -P -m pytest
67+
68+
- On older Python, you may enable :external+python:std:option:`isolated mode <-I>`
69+
(which stops adding the current directory to the import path, but has other
70+
repercussions)::
71+
72+
python -I -m pytest
73+
74+
- On any Python, set ``pytest``'s :external+pytest:doc:`import mode
75+
<explanation/pythonpath>` to the older ``prepend`` mode (but note that this will break
76+
``pytest``'s assert rewriting)::
77+
78+
python -m pytest --import-mode prepend
6179

6280
Viewing image test output
6381
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -302,11 +320,12 @@ is necessary for testing ``mpl_toolkits``.
302320

303321
Run the tests
304322
^^^^^^^^^^^^^
305-
To run the all the tests on your installed version of Matplotlib::
306323

307-
python -m pytest --pyargs matplotlib.tests
324+
To run all the tests on your installed version of Matplotlib::
325+
326+
pytest --pyargs matplotlib.tests
308327

309328
The test discovery scope can be narrowed to single test modules or even single
310329
functions::
311330

312-
python -m pytest --pyargs matplotlib.tests.test_simplification.py::test_clipping
331+
pytest --pyargs matplotlib.tests.test_simplification.py::test_clipping

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,6 @@ ignore_messages = [
298298
# `lib/matplotlib/testing/conftest.py`.
299299
minversion = "7.0"
300300
testpaths = ["lib"]
301+
addopts = [
302+
"--import-mode=importlib",
303+
]

0 commit comments

Comments
 (0)
0