Fix #6289 Co-authored-by: Ran Benita <ran234@gmail.com>
This commit is contained in:
parent
4021770688
commit
7c09d88b72
1
AUTHORS
1
AUTHORS
|
@ -194,6 +194,7 @@ Mihai Capotă
|
||||||
Mike Hoyle (hoylemd)
|
Mike Hoyle (hoylemd)
|
||||||
Mike Lundy
|
Mike Lundy
|
||||||
Miro Hrončok
|
Miro Hrončok
|
||||||
|
Nathaniel Compton
|
||||||
Nathaniel Waisbrot
|
Nathaniel Waisbrot
|
||||||
Ned Batchelder
|
Ned Batchelder
|
||||||
Neven Mundar
|
Neven Mundar
|
||||||
|
|
|
@ -234,11 +234,11 @@ expect a test to fail:
|
||||||
def test_function():
|
def test_function():
|
||||||
...
|
...
|
||||||
|
|
||||||
This test will be run but no traceback will be reported
|
This test will run but no traceback will be reported when it fails. Instead, terminal
|
||||||
when it fails. Instead terminal reporting will list it in the
|
reporting will list it in the "expected to fail" (``XFAIL``) or "unexpectedly
|
||||||
"expected to fail" (``XFAIL``) or "unexpectedly passing" (``XPASS``) sections.
|
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:
|
imperatively:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
@ -247,8 +247,19 @@ imperatively:
|
||||||
if not valid_config():
|
if not valid_config():
|
||||||
pytest.xfail("failing configuration (but should work)")
|
pytest.xfail("failing configuration (but should work)")
|
||||||
|
|
||||||
This will unconditionally make ``test_function`` ``XFAIL``. Note that no other code is executed
|
.. code-block:: python
|
||||||
after ``pytest.xfail`` call, differently from the marker. That's because it is implemented
|
|
||||||
|
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.
|
internally by raising a known exception.
|
||||||
|
|
||||||
**Reference**: :ref:`pytest.mark.xfail ref`
|
**Reference**: :ref:`pytest.mark.xfail ref`
|
||||||
|
@ -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
|
Both ``XFAIL`` and ``XPASS`` don't fail the test suite by default.
|
||||||
parameter is passed as ``True``:
|
You can change this by setting the ``strict`` keyword-only parameter to ``True``:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue