From f573fb65aa32c6517c79078685cae656779783ba Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 8 Nov 2023 15:02:00 -0500 Subject: [PATCH 1/2] Use `False`, instead of `None` as default for `_XfailMarkDecorator`'s `condition` param and update doc --- AUTHORS | 1 + changelog/11600.improvement.rst | 1 + doc/en/reference/reference.rst | 7 +++---- src/_pytest/mark/structures.py | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 changelog/11600.improvement.rst diff --git a/AUTHORS b/AUTHORS index 212d4a8832a..d8e90171504 100644 --- a/AUTHORS +++ b/AUTHORS @@ -339,6 +339,7 @@ Saiprasad Kale Samuel Colvin Samuel Dion-Girardeau Samuel Searles-Bryant +Samuel Therrien (Avasam) Samuele Pedroni Sanket Duthade Sankt Petersbug diff --git a/changelog/11600.improvement.rst b/changelog/11600.improvement.rst new file mode 100644 index 00000000000..7082e2c1e10 --- /dev/null +++ b/changelog/11600.improvement.rst @@ -0,0 +1 @@ +Improved the documentation and type signature for :func:`pytest.mark.xfail `'s ``condition`` param to use ``False`` as the default value. diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index 0240e1f4aad..c78ebf8c1ce 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -239,12 +239,11 @@ pytest.mark.xfail Marks a test function as *expected to fail*. -.. py:function:: pytest.mark.xfail(condition=None, *, reason=None, raises=None, run=True, strict=xfail_strict) +.. py:function:: pytest.mark.xfail(condition=False, *, reason=None, raises=None, run=True, strict=xfail_strict) - :type condition: bool or str - :param condition: + :keyword Union[bool, str] condition: Condition for marking the test function as xfail (``True/False`` or a - :ref:`condition string `). If a bool, you also have + :ref:`condition string `). If a ``bool``, you also have to specify ``reason`` (see :ref:`condition string `). :keyword str reason: Reason why the test function is marked as xfail. diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index bbde6864486..55ec67700b6 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -457,7 +457,7 @@ def __call__(self, arg: Markable) -> Markable: @overload def __call__( self, - condition: Union[str, bool] = ..., + condition: Union[str, bool] = False, *conditions: Union[str, bool], reason: str = ..., run: bool = ..., From 8d69964a4c98d9e48592a2b6ac81e4519c6268d2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:02:51 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/en/reference/reference.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index c78ebf8c1ce..f6dabb24510 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -241,7 +241,7 @@ Marks a test function as *expected to fail*. .. py:function:: pytest.mark.xfail(condition=False, *, reason=None, raises=None, run=True, strict=xfail_strict) - :keyword Union[bool, str] condition: + :keyword Union[bool, str] 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 `).