From 21e78b7bce873cca5047f413de6307859bc400f2 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 27 Oct 2023 18:26:29 -0400 Subject: [PATCH] Accept `None` in `_XfailMarkDecorator`'s `condition`param and expose default value --- AUTHORS | 1 + changelog/10094#issuecomment-1774215699.improvement.rst | 1 + doc/en/reference/reference.rst | 9 ++++----- src/_pytest/mark/structures.py | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 changelog/10094#issuecomment-1774215699.improvement.rst diff --git a/AUTHORS b/AUTHORS index 5ccff644c..0f120b421 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 000000000..92197a9c6 --- /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 d8efbbbaa..b7cf30055 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 bbde68644..157e1d93e 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -457,8 +457,8 @@ if TYPE_CHECKING: @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[