Skip to content

Commit b02f1c8

Browse files
committed
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).
1 parent bbd22e1 commit b02f1c8

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

CONTRIBUTING.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,20 +324,20 @@ Here is a simple overview, with pytest-specific bits:
324324
Writing Tests
325325
~~~~~~~~~~~~~
326326

327-
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.
327+
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.
328328

329329
For example, to ensure a simple test passes you can write:
330330

331331
.. code-block:: python
332332
333-
def test_true_assertion(testdir):
334-
testdir.makepyfile(
333+
def test_true_assertion(pytester):
334+
pytester.makepyfile(
335335
"""
336336
def test_foo():
337337
assert True
338338
"""
339339
)
340-
result = testdir.runpytest()
340+
result = pytester.runpytest()
341341
result.assert_outcomes(failed=0, passed=1)
342342
343343
@@ -346,14 +346,14 @@ Alternatively, it is possible to make checks based on the actual output of the t
346346

347347
.. code-block:: python
348348
349-
def test_true_assertion(testdir):
350-
testdir.makepyfile(
349+
def test_true_assertion(pytester):
350+
pytester.makepyfile(
351351
"""
352352
def test_foo():
353353
assert False
354354
"""
355355
)
356-
result = testdir.runpytest()
356+
result = pytester.runpytest()
357357
result.stdout.fnmatch_lines(["*assert False*", "*1 failed*"])
358358
359359
When choosing a file where to write a new test, take a look at the existing files and see if there's

doc/en/writing_plugins.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ testing directory:
337337
Alternatively you can invoke pytest with the ``-p pytester`` command line
338338
option.
339339

340-
This will allow you to use the :py:class:`testdir <_pytest.pytester.Testdir>`
340+
This will allow you to use the :py:class:`pytester <_pytest.pytester.Pytester>`
341341
fixture for testing your plugin code.
342342

343343
Let's demonstrate what you can do with the plugin with an example. Imagine we
@@ -374,17 +374,17 @@ string value of ``Hello World!`` if we do not supply a value or ``Hello
374374
return _hello
375375
376376
377-
Now the ``testdir`` fixture provides a convenient API for creating temporary
377+
Now the ``pytester`` fixture provides a convenient API for creating temporary
378378
``conftest.py`` files and test files. It also allows us to run the tests and
379379
return a result object, with which we can assert the tests' outcomes.
380380

381381
.. code-block:: python
382382
383-
def test_hello(testdir):
383+
def test_hello(pytester):
384384
"""Make sure that our plugin works."""
385385
386386
# create a temporary conftest.py file
387-
testdir.makeconftest(
387+
pytester.makeconftest(
388388
"""
389389
import pytest
390390
@@ -399,7 +399,7 @@ return a result object, with which we can assert the tests' outcomes.
399399
)
400400
401401
# create a temporary pytest test file
402-
testdir.makepyfile(
402+
pytester.makepyfile(
403403
"""
404404
def test_hello_default(hello):
405405
assert hello() == "Hello World!"
@@ -410,7 +410,7 @@ return a result object, with which we can assert the tests' outcomes.
410410
)
411411
412412
# run all tests with pytest
413-
result = testdir.runpytest()
413+
result = pytester.runpytest()
414414
415415
# check that all 4 tests passed
416416
result.assert_outcomes(passed=4)
@@ -430,9 +430,9 @@ Additionally it is possible to copy examples for an example folder before runnin
430430
# content of test_example.py
431431
432432
433-
def test_plugin(testdir):
434-
testdir.copy_example("test_example.py")
435-
testdir.runpytest("-k", "test_example")
433+
def test_plugin(pytester):
434+
pytester.copy_example("test_example.py")
435+
pytester.runpytest("-k", "test_example")
436436
437437
438438
def test_example():

0 commit comments

Comments
 (0)