From b02f1c8ae74d8c5273e3d651539e931af64c34fa Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Fri, 1 Jan 2021 12:21:39 -0800 Subject: 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). --- CONTRIBUTING.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'CONTRIBUTING.rst') 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 `_, as a "black-box" test. +Writing tests for plugins or for pytest itself is often done using the `pytester fixture `_, 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 -- cgit v1.2.3