From d4c56c72d8a623414da9ec9bd76a00bb844c71e4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Nov 2023 21:00:52 +0000 Subject: [PATCH 1/4] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 23.10.1 → 23.11.0](https://github.com/psf/black/compare/23.10.1...23.11.0) - [github.com/pre-commit/mirrors-mypy: v1.6.1 → v1.7.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.6.1...v1.7.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0f7e4b2a7..1fb026602 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: 23.10.1 + rev: 23.11.0 hooks: - id: black args: [--safe, --quiet] @@ -56,7 +56,7 @@ repos: hooks: - id: python-use-type-annotations - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.6.1 + rev: v1.7.0 hooks: - id: mypy files: ^(src/|testing/) From 970d11cf348b45e830a0b9b3a3d70c511b4d517e Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 14 Nov 2023 07:29:40 -0300 Subject: [PATCH 2/4] Explicitly export error and path from py Required by mypy 1.7.0 --- src/py.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/py.py b/src/py.py index 7813c9b93..c99790336 100644 --- a/src/py.py +++ b/src/py.py @@ -8,3 +8,5 @@ import _pytest._py.path as path sys.modules["py.error"] = error sys.modules["py.path"] = path + +__all__ = ["error", "path"] From 223e030604d1f5de54fe07cdb12689aa46556e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 14 Nov 2023 15:41:35 +0100 Subject: [PATCH 3/4] XFAIL TestLocalPath.test_make_numbered_dir_multiprocess_safe (#11611) The tested py.path.local.make_numbered_dir function is *not* multiprocess safe, because is uses os.listdir which itself is not. The os.listdir documentation explicitly states that: > If a file is removed from or added to the directory during the call > of this function, whether a name for that file be included is unspecified. This can lead to a race when: 1. process A attempts to create directory N 2. the creation fails, as another process already created it in the meantime 3. process A calls listdir to determine a more recent maxnum 4. processes B+ repeatedly create newer directories and they delete directory N 5. process A doesn't have directory N or any newer directory in listdir result 6. process A attempts to create directory N again and raises For details, see https://github.com/pytest-dev/pytest/issues/11603#issuecomment-1805708144 and bellow. Additionally, the test itself has a race in batch_make_numbered_dirs. When this functions attempts to write to repro-N/foo, repro-N may have already been removed by another process. For details, see https://github.com/pytest-dev/pytest/issues/11603#issuecomment-1804714313 and bellow. --- The tested py.path.local.make_numbered_dir function is not used in pytest. There is a different implementation in _pytest.pathlib. Closes #11603 --- testing/_py/test_local.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/_py/test_local.py b/testing/_py/test_local.py index aebee380c..77a9838cf 100644 --- a/testing/_py/test_local.py +++ b/testing/_py/test_local.py @@ -868,6 +868,9 @@ class TestLocalPath(CommonFSTests): py_path.strpath, str_path ) + @pytest.mark.xfail( + reason="#11603", raises=(error.EEXIST, error.ENOENT), strict=False + ) def test_make_numbered_dir_multiprocess_safe(self, tmpdir): # https://github.com/pytest-dev/py/issues/30 with multiprocessing.Pool() as pool: From 80442ae2f2177039e5395d8a26fc6e3ca3a54f3e Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 17 Nov 2023 03:42:05 -0500 Subject: [PATCH 4/4] Use `False`, instead of `None` as default for `_XfailMarkDecorator`'s `condition` param and update doc (#11600) --- 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 212d4a883..d8e901715 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 000000000..7082e2c1e --- /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 0240e1f4a..f6dabb245 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 bbde68644..55ec67700 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -457,7 +457,7 @@ if TYPE_CHECKING: @overload def __call__( self, - condition: Union[str, bool] = ..., + condition: Union[str, bool] = False, *conditions: Union[str, bool], reason: str = ..., run: bool = ...,