Skip to content

Commit 69419cb

Browse files
authored
New pytester fixture (#7854)
1 parent cb578a9 commit 69419cb

File tree

7 files changed

+632
-389
lines changed

7 files changed

+632
-389
lines changed

changelog/7425.feature.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
New :fixture:`pytester` fixture, which is identical to :fixture:`testdir` but its methods return :class:`pathlib.Path` when appropriate instead of ``py.path.local``.
2+
3+
This is part of the movement to use :class:`pathlib.Path` objects internally, in order to remove the dependency to ``py`` in the future.
4+
5+
Internally, the old :class:`Testdir` is now a thin wrapper around :class:`Pytester`, preserving the old interface.

doc/en/reference.rst

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,25 +499,29 @@ monkeypatch
499499
:members:
500500

501501

502-
.. fixture:: testdir
502+
.. fixture:: pytester
503503

504-
testdir
505-
~~~~~~~
504+
pytester
505+
~~~~~~~~
506+
507+
.. versionadded:: 6.2
506508

507509
.. currentmodule:: _pytest.pytester
508510

509-
This fixture provides a :class:`Testdir` instance useful for black-box testing of test files, making it ideal to
510-
test plugins.
511+
Provides a :class:`Pytester` instance that can be used to run and test pytest itself.
512+
513+
It provides an empty directory where pytest can be executed in isolation, and contains facilities
514+
to write tests, configuration files, and match against expected output.
511515

512-
To use it, include in your top-most ``conftest.py`` file:
516+
To use it, include in your topmost ``conftest.py`` file:
513517

514518
.. code-block:: python
515519
516520
pytest_plugins = "pytester"
517521
518522
519523
520-
.. autoclass:: Testdir()
524+
.. autoclass:: Pytester()
521525
:members:
522526

523527
.. autoclass:: RunResult()
@@ -526,6 +530,15 @@ To use it, include in your top-most ``conftest.py`` file:
526530
.. autoclass:: LineMatcher()
527531
:members:
528532

533+
.. fixture:: testdir
534+
535+
testdir
536+
~~~~~~~
537+
538+
Identical to :fixture:`pytester`, but provides an instance whose methods return
539+
legacy ``py.path.local`` objects instead when applicable.
540+
541+
New code should avoid using :fixture:`testdir` in favor of :fixture:`pytester`.
529542

530543
.. fixture:: recwarn
531544

0 commit comments

Comments
 (0)