diff options
author | Hong Xu <hong@topbug.net> | 2021-01-01 12:21:39 -0800 |
---|---|---|
committer | Hong Xu <hong@topbug.net> | 2021-01-01 12:21:39 -0800 |
commit | b02f1c8ae74d8c5273e3d651539e931af64c34fa (patch) | |
tree | c25b751a71327295c748597b350f1f374cda19f9 /CONTRIBUTING.rst | |
parent | bbd22e1769e22ebd4af6c7959b3789914db87fa4 (diff) | |
download | pytest-b02f1c8ae74d8c5273e3d651539e931af64c34fa.tar.gz |
DOC: Update multiple references to testdir to pytester
In https://docs.pytest.org/en/stable/reference.html#testdir, it is
suggested:
> New code should avoid using testdir in favor of pytester.
Multiple spots in the documents still use testdir and they can be quite
confusing (especially the plugin writing guide).
Diffstat (limited to 'CONTRIBUTING.rst')
-rw-r--r-- | CONTRIBUTING.rst | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 2669cb195..054f809a8 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -324,20 +324,20 @@ Here is a simple overview, with pytest-specific bits: Writing Tests ~~~~~~~~~~~~~ -Writing tests for plugins or for pytest itself is often done using the `testdir fixture <https://docs.pytest.org/en/stable/reference.html#testdir>`_, as a "black-box" test. +Writing tests for plugins or for pytest itself is often done using the `pytester fixture <https://docs.pytest.org/en/stable/reference.html#pytester>`_, as a "black-box" test. For example, to ensure a simple test passes you can write: .. code-block:: python - def test_true_assertion(testdir): - testdir.makepyfile( + def test_true_assertion(pytester): + pytester.makepyfile( """ def test_foo(): assert True """ ) - result = testdir.runpytest() + result = pytester.runpytest() result.assert_outcomes(failed=0, passed=1) @@ -346,14 +346,14 @@ Alternatively, it is possible to make checks based on the actual output of the t .. code-block:: python - def test_true_assertion(testdir): - testdir.makepyfile( + def test_true_assertion(pytester): + pytester.makepyfile( """ def test_foo(): assert False """ ) - result = testdir.runpytest() + result = pytester.runpytest() result.stdout.fnmatch_lines(["*assert False*", "*1 failed*"]) When choosing a file where to write a new test, take a look at the existing files and see if there's |