From 661013c3e922c17f2dcf90a96bcc74b95a681475 Mon Sep 17 00:00:00 2001 From: Tomer Keren Date: Mon, 15 Oct 2018 11:13:24 +0300 Subject: Add testdir examples to CONTRIBUTING guide Hopefully Closes: #4151 --- CONTRIBUTING.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index c005c2fb2..eb36122b5 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -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 `_, + +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 ---------------------------- -- cgit v1.2.3