Skip to content

Commit

Permalink
#6289: Add new example to XFAIL documentation (#6685)
Browse files Browse the repository at this point in the history
Fix #6289

Co-authored-by: Ran Benita <ran234@gmail.com>
  • Loading branch information
nathanielcompton and bluetech committed Feb 19, 2020
1 parent 4021770 commit 7c09d88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -194,6 +194,7 @@ Mihai Capotă
Mike Hoyle (hoylemd)
Mike Lundy
Miro Hrončok
Nathaniel Compton
Nathaniel Waisbrot
Ned Batchelder
Neven Mundar
Expand Down
27 changes: 19 additions & 8 deletions doc/en/skipping.rst
Expand Up @@ -234,11 +234,11 @@ expect a test to fail:
def test_function():
...
This test will be run but no traceback will be reported
when it fails. Instead terminal reporting will list it in the
"expected to fail" (``XFAIL``) or "unexpectedly passing" (``XPASS``) sections.
This test will run but no traceback will be reported when it fails. Instead, terminal
reporting will list it in the "expected to fail" (``XFAIL``) or "unexpectedly
passing" (``XPASS``) sections.

Alternatively, you can also mark a test as ``XFAIL`` from within a test or setup function
Alternatively, you can also mark a test as ``XFAIL`` from within the test or its setup function
imperatively:

.. code-block:: python
Expand All @@ -247,8 +247,19 @@ imperatively:
if not valid_config():
pytest.xfail("failing configuration (but should work)")
This will unconditionally make ``test_function`` ``XFAIL``. Note that no other code is executed
after ``pytest.xfail`` call, differently from the marker. That's because it is implemented
.. code-block:: python
def test_function2():
import slow_module
if slow_module.slow_function():
pytest.xfail("slow_module taking too long")
These two examples illustrate situations where you don't want to check for a condition
at the module level, which is when a condition would otherwise be evaluated for marks.

This will make ``test_function`` ``XFAIL``. Note that no other code is executed after
the ``pytest.xfail`` call, differently from the marker. That's because it is implemented
internally by raising a known exception.

**Reference**: :ref:`pytest.mark.xfail ref`
Expand All @@ -261,8 +272,8 @@ internally by raising a known exception.



Both ``XFAIL`` and ``XPASS`` don't fail the test suite, unless the ``strict`` keyword-only
parameter is passed as ``True``:
Both ``XFAIL`` and ``XPASS`` don't fail the test suite by default.
You can change this by setting the ``strict`` keyword-only parameter to ``True``:

.. code-block:: python
Expand Down

0 comments on commit 7c09d88

Please sign in to comment.