Skip to content

Accept None in _XfailMarkDecorator's conditionparam and expose default value #11565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ Saiprasad Kale
Samuel Colvin
Samuel Dion-Girardeau
Samuel Searles-Bryant
Samuel Therrien (Avasam)
Samuele Pedroni
Sanket Duthade
Sankt Petersbug
Expand Down
1 change: 1 addition & 0 deletions changelog/10094#issuecomment-1774215699.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved the documentation and type signature for :func:`pytest.mark.xfail <pytest.mark.xfail>`'s ``condition`` param to support ``None``.
9 changes: 4 additions & 5 deletions doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,10 @@ Marks a test function as *expected to fail*.

.. py:function:: pytest.mark.xfail(condition=None, *, reason=None, raises=None, run=True, strict=xfail_strict)

:type condition: bool or str
:param condition:
Condition for marking the test function as xfail (``True/False`` or a
:ref:`condition string <string conditions>`). If a bool, you also have
to specify ``reason`` (see :ref:`condition string <string conditions>`).
:keyword Optional[Union[bool, str]] condition:
Condition for marking the test function as xfail (``True/False/None`` or a
:ref:`condition string <string conditions>`). If a bool or None, you also have
to specify ``reason`` (see :ref:`condition string <string conditions>`). ``None`` is the same as ``False``.
:keyword str reason:
Reason why the test function is marked as xfail.
:keyword Type[Exception] raises:
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/mark/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ def __call__(self, arg: Markable) -> Markable:
@overload
def __call__(
self,
condition: Union[str, bool] = ...,
*conditions: Union[str, bool],
condition: Optional[Union[str, bool]] = None,
*conditions: Optional[Union[str, bool]],
reason: str = ...,
run: bool = ...,
raises: Union[
Expand Down