Skip to content

Commit 1005686

Browse files
authored
Merge pull request #11309 from bluetech/docs-xfail
doc: fix a few `xfail` nits
2 parents 556e075 + 1827d8d commit 1005686

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

doc/en/reference/reference.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pytest.mark.xfail
237237

238238
Marks a test function as *expected to fail*.
239239

240-
.. py:function:: pytest.mark.xfail(condition=None, *, reason=None, raises=None, run=True, strict=False)
240+
.. py:function:: pytest.mark.xfail(condition=None, *, reason=None, raises=None, run=True, strict=xfail_strict)
241241
242242
:type condition: bool or str
243243
:param condition:
@@ -249,17 +249,19 @@ Marks a test function as *expected to fail*.
249249
:keyword Type[Exception] raises:
250250
Exception subclass (or tuple of subclasses) expected to be raised by the test function; other exceptions will fail the test.
251251
:keyword bool run:
252-
If the test function should actually be executed. If ``False``, the function will always xfail and will
252+
Whether the test function should actually be executed. If ``False``, the function will always xfail and will
253253
not be executed (useful if a function is segfaulting).
254254
:keyword bool strict:
255-
* If ``False`` (the default) the function will be shown in the terminal output as ``xfailed`` if it fails
255+
* If ``False`` the function will be shown in the terminal output as ``xfailed`` if it fails
256256
and as ``xpass`` if it passes. In both cases this will not cause the test suite to fail as a whole. This
257257
is particularly useful to mark *flaky* tests (tests that fail at random) to be tackled later.
258258
* If ``True``, the function will be shown in the terminal output as ``xfailed`` if it fails, but if it
259259
unexpectedly passes then it will **fail** the test suite. This is particularly useful to mark functions
260260
that are always failing and there should be a clear indication if they unexpectedly start to pass (for example
261261
a new release of a library fixes a known bug).
262262

263+
Defaults to :confval:`xfail_strict`, which is ``False`` by default.
264+
263265

264266
Custom marks
265267
~~~~~~~~~~~~

src/_pytest/mark/structures.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,9 @@ def __call__(
461461
*conditions: Union[str, bool],
462462
reason: str = ...,
463463
run: bool = ...,
464-
raises: Union[Type[BaseException], Tuple[Type[BaseException], ...]] = ...,
464+
raises: Union[
465+
None, Type[BaseException], Tuple[Type[BaseException], ...]
466+
] = ...,
465467
strict: bool = ...,
466468
) -> MarkDecorator:
467469
...

src/_pytest/outcomes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ def xfail(reason: str = "") -> NoReturn:
233233
234234
This function should be called only during testing (setup, call or teardown).
235235
236+
No other code is executed after using ``xfail()`` (it is implemented
237+
internally by raising an exception).
238+
236239
:param reason:
237240
The message to show the user as reason for the xfail.
238241

0 commit comments

Comments
 (0)