Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump min pytest to 7.0.0 #1058

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ repos:
files: ^(src/|testing/)
args: []
additional_dependencies:
- pytest>=6.2.0
- pytest>=7.0.0
- py>=1.10.0
1 change: 1 addition & 0 deletions changelog/1057.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest>=7.0.0 is now required.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ classifiers = [
requires-python = ">=3.8"
dependencies = [
"execnet>=1.1",
"pytest>=6.2.0",
"pytest>=7.0.0",
]
dynamic = ["version"]

Expand Down
4 changes: 1 addition & 3 deletions src/xdist/dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ def worker_internal_error(self, node, formatted_error):
try:
assert False, formatted_error
except AssertionError:
from _pytest._code import ExceptionInfo

excinfo = ExceptionInfo.from_current()
excinfo = pytest.ExceptionInfo.from_current()
excrepr = excinfo.getrepr()
self.config.hook.pytest_internalerror(excrepr=excrepr, excinfo=excinfo)

Expand Down
2 changes: 1 addition & 1 deletion src/xdist/looponfail.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def init_worker_session(channel, args, option_dict):
sys.path[:] = newpaths

# fullwidth, hasmarkup = channel.receive()
from _pytest.config import Config
from pytest import Config

config = Config.fromdictargs(option_dict, list(args))
config.args = args
Expand Down
8 changes: 3 additions & 5 deletions src/xdist/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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.",
)

Expand Down
7 changes: 1 addition & 6 deletions src/xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,9 @@ def pytest_collection_modifyitems(self, session, config, items):

@pytest.hookimpl
def pytest_collection_finish(self, session):
try:
topdir = str(self.config.rootpath)
except AttributeError: # pytest <= 6.1.0
topdir = str(self.config.rootdir)

self.sendevent(
"collectionfinish",
topdir=topdir,
topdir=str(self.config.rootpath),
ids=[item.nodeid for item in session.items],
)

Expand Down
9 changes: 6 additions & 3 deletions src/xdist/scheduler/load.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from itertools import cycle

from _pytest.runner import CollectReport
import pytest

from xdist.remote import Producer
from xdist.report import report_collection_diff
Expand Down Expand Up @@ -307,8 +307,11 @@ def _check_nodes_have_same_collection(self):
same_collection = False
self.log(msg)
if self.config is not None:
rep = CollectReport(
node.gateway.id, "failed", longrepr=msg, result=[]
rep = pytest.CollectReport(
nodeid=node.gateway.id,
outcome="failed",
longrepr=msg,
result=[],
)
self.config.hook.pytest_collectreport(report=rep)

Expand Down
9 changes: 7 additions & 2 deletions src/xdist/scheduler/loadscope.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import OrderedDict

from _pytest.runner import CollectReport
import pytest

from xdist.remote import Producer
from xdist.report import report_collection_diff
Expand Down Expand Up @@ -410,7 +410,12 @@ def _check_nodes_have_same_collection(self):
if self.config is None:
continue

rep = CollectReport(node.gateway.id, "failed", longrepr=msg, result=[])
rep = pytest.CollectReport(
nodeid=node.gateway.id,
outcome="failed",
longrepr=msg,
result=[],
)
self.config.hook.pytest_collectreport(report=rep)

return same_collection
9 changes: 6 additions & 3 deletions src/xdist/scheduler/worksteal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any
from typing import NamedTuple

from _pytest.runner import CollectReport
import pytest

from xdist.remote import Producer
from xdist.report import report_collection_diff
Expand Down Expand Up @@ -323,8 +323,11 @@ def _check_nodes_have_same_collection(self):
same_collection = False
self.log(msg)
if self.config is not None:
rep = CollectReport(
node.gateway.id, "failed", longrepr=msg, result=[]
rep = pytest.CollectReport(
nodeid=node.gateway.id,
outcome="failed",
longrepr=msg,
result=[],
)
self.config.hook.pytest_collectreport(report=rep)

Expand Down
4 changes: 1 addition & 3 deletions src/xdist/workermanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,7 @@ def process_from_remote(self, eventcall):
# should not land in receiver-thread
raise
except BaseException:
from _pytest._code import ExceptionInfo

excinfo = ExceptionInfo.from_current()
excinfo = pytest.ExceptionInfo.from_current()
print("!" * 20, excinfo)
self.config.notify_exception(excinfo)
self.shutdown()
Expand Down
5 changes: 1 addition & 4 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,14 +1112,11 @@ def test_error_report_styles():
result.assert_outcomes(failed=1)


def test_color_yes_collection_on_non_atty(pytester, request) -> None:
def test_color_yes_collection_on_non_atty(pytester) -> None:
"""Skip collect progress report when working on non-terminals.

Similar to pytest-dev/pytest#1397
"""
tr = request.config.pluginmanager.getplugin("terminalreporter")
if not hasattr(tr, "isatty"):
pytest.skip("only valid for newer pytest versions")
pytester.makepyfile(
"""
import pytest
Expand Down
28 changes: 8 additions & 20 deletions testing/test_looponfail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -259,7 +248,7 @@ def test_two():
"""
)
)
removepyc(modcol_path)
removepyc(modcol.path)
remotecontrol.loop_once()
assert not remotecontrol.failures

Expand All @@ -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():
Expand All @@ -288,7 +276,7 @@ def test_two():
"""
)
)
removepyc(modcol_path)
removepyc(modcol.path)
remotecontrol.loop_once()
assert len(remotecontrol.failures) == 0
remotecontrol.loop_once()
Expand Down
4 changes: 1 addition & 3 deletions testing/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,7 @@ def test_mainargv(request):
assert result.ret == 0


def test_remote_usage_prog(pytester: pytest.Pytester, request) -> None:
if not hasattr(request.config._parser, "prog"):
pytest.skip("prog not available in config parser")
def test_remote_usage_prog(pytester: pytest.Pytester) -> None:
pytester.makeconftest(
"""
import pytest
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down