diff --git a/AUTHORS b/AUTHORS index 5ccff644c1c..0f120b42167 100644 --- a/AUTHORS +++ b/AUTHORS @@ -338,6 +338,7 @@ Saiprasad Kale Samuel Colvin Samuel Dion-Girardeau Samuel Searles-Bryant +Samuel Therrien (Avasam) Samuele Pedroni Sanket Duthade Sankt Petersbug diff --git a/changelog/10094#issuecomment-1774215699.improvement.rst b/changelog/10094#issuecomment-1774215699.improvement.rst new file mode 100644 index 00000000000..92197a9c69e --- /dev/null +++ b/changelog/10094#issuecomment-1774215699.improvement.rst @@ -0,0 +1 @@ +Improved the documentation and type signature for :func:`pytest.mark.xfail `'s ``condition`` param to support ``None``. diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index d8efbbbaadc..6bf0e1b27c3 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -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 `). If a bool, you also have - to specify ``reason`` (see :ref:`condition string `). + :keyword Optional[Union[bool, str]] condition: + Condition for marking the test function as xfail (``True/False/None`` or a + :ref:`condition string `). If a bool or None, you also have + to specify ``reason`` (see :ref:`condition string `). ``None`` is the same as ``False``. :keyword str reason: Reason why the test function is marked as xfail. :keyword Type[Exception] raises: diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index bbde6864486..157e1d93e36 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -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[