Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New testdir-like fixture using pathlib #7425

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/7425.feature.rst
@@ -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
Expand Up @@ -494,25 +494,27 @@ monkeypatch
:members:


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

testdir
~~~~~~~
test_path
nicoddemus marked this conversation as resolved.
Show resolved Hide resolved
~~~~~~~~~

.. 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