Add testdir examples to CONTRIBUTING guide

Hopefully Closes: #4151
This commit is contained in:
Tomer Keren 2018-10-15 11:13:24 +03:00
parent 49defa2890
commit 661013c3e9
1 changed files with 31 additions and 0 deletions

View File

@ -280,6 +280,37 @@ Here is a simple overview, with pytest-specific bits:
base: features # if it's a feature
Writing Tests
----------------------------
Writing tests for plugins or for pytest itself is done using the `testdir fixture <https://docs.pytest.org/en/latest/reference.html#testdir>`_,
For example:
.. code-block:: python
def test_true_assertion(testdir):
testdir.makepyfile(
"""
def test_foo():
assert True
"""
)
result = testdir.runpytest()
result.assert_outcomes(failed=0, passed=1)
def test_true_assertion(testdir):
testdir.makepyfile(
"""
def test_foo():
assert False
"""
)
result = testdir.runpytest()
result.assert_outcomes(failed=1, passed=0)
Joining the Development Team
----------------------------