Skip to content

Commit

Permalink
Add TestPath class and test_path fixture
Browse files Browse the repository at this point in the history
Also change Testdir to be a thin wrapper which only delegates to TestPath. An
alternative would be to subclass and only overwrite the methods that return
Path to convert the return to py.path.local, but this was preferred so we don't
expose Path-returning objects by accident and to expose exactly what we want
in Testdir.
  • Loading branch information
nicoddemus committed Jul 11, 2020
1 parent ded45e0 commit 5eba34a
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 71 deletions.
3 changes: 3 additions & 0 deletions changelog/7425.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
New :fixture:`test_path` fixture, which is identical to :fixture:`testdir` but its methods return :class:`pathlib.Path` when appropriate instead of ``py.path.local``.

This is part of the movement to use :class:`pathlib.Path` objects internally, in order to remove the dependency to ``py`` in the future.
25 changes: 18 additions & 7 deletions doc/en/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -494,25 +494,27 @@ monkeypatch
:members:


.. fixture:: testdir
.. fixture:: test_path

testdir
~~~~~~~
test_path
~~~~~~~~~

.. currentmodule:: _pytest.pytester

This fixture provides a :class:`Testdir` instance useful for black-box testing of test files, making it ideal to
test plugins.
Provides a :class:`TestPath` instance that can be used to run and test pytest itself.

It provides an empty folder where pytest can be executed in isolation, and contains facilities
to write test, configuration files, and match against expected output.

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

.. code-block:: python
pytest_plugins = "pytester"
.. autoclass:: Testdir()
.. autoclass:: TestPath()
:members:

.. autoclass:: RunResult()
Expand All @@ -521,6 +523,15 @@ To use it, include in your top-most ``conftest.py`` file:
.. autoclass:: LineMatcher()
:members:

.. fixture:: testdir

testdir
~~~~~~~

Identical to :fixture:`test_path`, but provides an instance whose methods return
legacy ``py.path.local`` objects instead when applicable.

New code should avoid using :fixture:`testdir` in favor of :fixture:`test_path`.

.. fixture:: recwarn

Expand Down

0 comments on commit 5eba34a

Please sign in to comment.