From 385ebd69c183146efe70be74c76558c3cdf7d0f7 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 4 Apr 2024 19:52:09 +0300 Subject: [PATCH] Bump min pytest to 7.0.0 Refs #1057 --- changelog/1057.removal | 1 + pyproject.toml | 2 +- src/xdist/plugin.py | 8 +++----- testing/test_looponfail.py | 28 ++++++++-------------------- tox.ini | 2 +- 5 files changed, 14 insertions(+), 27 deletions(-) create mode 100644 changelog/1057.removal diff --git a/changelog/1057.removal b/changelog/1057.removal new file mode 100644 index 00000000..fbd9c5d6 --- /dev/null +++ b/changelog/1057.removal @@ -0,0 +1 @@ +pytest>=7.0.0 is now required. diff --git a/pyproject.toml b/pyproject.toml index 651e8995..144df633 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ classifiers = [ requires-python = ">=3.8" dependencies = [ "execnet>=1.1", - "pytest>=6.2.0", + "pytest>=7.0.0", ] dynamic = ["version"] diff --git a/src/xdist/plugin.py b/src/xdist/plugin.py index c9d4c49c..14d081f7 100644 --- a/src/xdist/plugin.py +++ b/src/xdist/plugin.py @@ -6,8 +6,6 @@ import pytest -PYTEST_GTE_7 = hasattr(pytest, "version_tuple") and pytest.version_tuple >= (7, 0) # type: ignore[attr-defined] - _sys_path = list(sys.path) # freeze a copy of sys.path at interpreter startup @@ -188,16 +186,16 @@ def pytest_addoption(parser): parser.addini( "rsyncdirs", "list of (relative) paths to be rsynced for remote distributed testing.", - type="paths" if PYTEST_GTE_7 else "pathlist", + type="paths", ) parser.addini( "rsyncignore", "list of (relative) glob-style paths to be ignored for rsyncing.", - type="paths" if PYTEST_GTE_7 else "pathlist", + type="paths", ) parser.addini( "looponfailroots", - type="paths" if PYTEST_GTE_7 else "pathlist", + type="paths", help="directories to check for changes. Default: current directory.", ) diff --git a/testing/test_looponfail.py b/testing/test_looponfail.py index 2879e4d9..348aa3e8 100644 --- a/testing/test_looponfail.py +++ b/testing/test_looponfail.py @@ -12,9 +12,6 @@ from xdist.looponfail import StatRecorder -PYTEST_GTE_7 = hasattr(pytest, "version_tuple") and pytest.version_tuple >= (7, 0) # type: ignore[attr-defined] - - class TestStatRecorder: def test_filechange(self, tmp_path: Path) -> None: tmp = tmp_path @@ -128,9 +125,8 @@ def test_failures_somewhere(self, pytester: pytest.Pytester) -> None: failures = control.runsession() assert failures control.setup() - item_path = item.path if PYTEST_GTE_7 else Path(str(item.fspath)) # type: ignore[attr-defined] - item_path.write_text("def test_func():\n assert 1\n") - removepyc(item_path) + item.path.write_text("def test_func():\n assert 1\n") + removepyc(item.path) topdir, failures = control.runsession()[:2] assert not failures @@ -146,10 +142,7 @@ def test_func(): control = RemoteControl(modcol.config) control.loop_once() assert control.failures - if PYTEST_GTE_7: - modcol_path = modcol.path # type:ignore[attr-defined] - else: - modcol_path = Path(str(modcol.fspath)) + modcol_path = modcol.path # type:ignore[attr-defined] modcol_path.write_text( textwrap.dedent( @@ -179,10 +172,7 @@ def test_func(): """ ) ) - if PYTEST_GTE_7: - parent = modcol.path.parent.parent # type: ignore[attr-defined] - else: - parent = Path(modcol.fspath.dirpath().dirpath()) + parent = modcol.path.parent.parent # type: ignore[attr-defined] monkeypatch.chdir(parent) modcol.config.args = [ str(Path(x).relative_to(parent)) for x in modcol.config.args @@ -248,8 +238,7 @@ def test_two(): remotecontrol.loop_once() assert len(remotecontrol.failures) == 1 - modcol_path = modcol.path if PYTEST_GTE_7 else Path(modcol.fspath) - modcol_path.write_text( + modcol.path.write_text( textwrap.dedent( """ def test_one(): @@ -259,7 +248,7 @@ def test_two(): """ ) ) - removepyc(modcol_path) + removepyc(modcol.path) remotecontrol.loop_once() assert not remotecontrol.failures @@ -277,8 +266,7 @@ def test_one(): assert len(remotecontrol.failures) == 1 assert "test_one" in remotecontrol.failures[0] - modcol_path = modcol.path if PYTEST_GTE_7 else Path(modcol.fspath) - modcol_path.write_text( + modcol.path.write_text( textwrap.dedent( """ def test_one(): @@ -288,7 +276,7 @@ def test_two(): """ ) ) - removepyc(modcol_path) + removepyc(modcol.path) remotecontrol.loop_once() assert len(remotecontrol.failures) == 0 remotecontrol.loop_once() diff --git a/tox.ini b/tox.ini index c4f24387..6a3e9db2 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ isolated_build = true [testenv] extras = testing deps = - pytestmin: pytest==6.2.0 + pytestmin: pytest==7.0.0 pytestlatest: pytest pytestmain: git+https://github.com/pytest-dev/pytest.git commands=