Skip to content

Commit dd067e4

Browse files
authored
Merge pull request #1058 from bluetech/pytest-min-7
Bump min pytest to 7.0.0
2 parents 99b767b + 31de42f commit dd067e4

15 files changed

+40
-56
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ repos:
2929
files: ^(src/|testing/)
3030
args: []
3131
additional_dependencies:
32-
- pytest>=6.2.0
32+
- pytest>=7.0.0
3333
- py>=1.10.0

changelog/1057.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest>=7.0.0 is now required.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ classifiers = [
3434
requires-python = ">=3.8"
3535
dependencies = [
3636
"execnet>=1.1",
37-
"pytest>=6.2.0",
37+
"pytest>=7.0.0",
3838
]
3939
dynamic = ["version"]
4040

src/xdist/dsession.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ def worker_internal_error(self, node, formatted_error):
206206
try:
207207
assert False, formatted_error
208208
except AssertionError:
209-
from _pytest._code import ExceptionInfo
210-
211-
excinfo = ExceptionInfo.from_current()
209+
excinfo = pytest.ExceptionInfo.from_current()
212210
excrepr = excinfo.getrepr()
213211
self.config.hook.pytest_internalerror(excrepr=excrepr, excinfo=excinfo)
214212

src/xdist/looponfail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def init_worker_session(channel, args, option_dict):
168168
sys.path[:] = newpaths
169169

170170
# fullwidth, hasmarkup = channel.receive()
171-
from _pytest.config import Config
171+
from pytest import Config
172172

173173
config = Config.fromdictargs(option_dict, list(args))
174174
config.args = args

src/xdist/plugin.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import pytest
77

88

9-
PYTEST_GTE_7 = hasattr(pytest, "version_tuple") and pytest.version_tuple >= (7, 0) # type: ignore[attr-defined]
10-
119
_sys_path = list(sys.path) # freeze a copy of sys.path at interpreter startup
1210

1311

@@ -188,16 +186,16 @@ def pytest_addoption(parser):
188186
parser.addini(
189187
"rsyncdirs",
190188
"list of (relative) paths to be rsynced for remote distributed testing.",
191-
type="paths" if PYTEST_GTE_7 else "pathlist",
189+
type="paths",
192190
)
193191
parser.addini(
194192
"rsyncignore",
195193
"list of (relative) glob-style paths to be ignored for rsyncing.",
196-
type="paths" if PYTEST_GTE_7 else "pathlist",
194+
type="paths",
197195
)
198196
parser.addini(
199197
"looponfailroots",
200-
type="paths" if PYTEST_GTE_7 else "pathlist",
198+
type="paths",
201199
help="directories to check for changes. Default: current directory.",
202200
)
203201

src/xdist/remote.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,9 @@ def pytest_collection_modifyitems(self, session, config, items):
201201

202202
@pytest.hookimpl
203203
def pytest_collection_finish(self, session):
204-
try:
205-
topdir = str(self.config.rootpath)
206-
except AttributeError: # pytest <= 6.1.0
207-
topdir = str(self.config.rootdir)
208-
209204
self.sendevent(
210205
"collectionfinish",
211-
topdir=topdir,
206+
topdir=str(self.config.rootpath),
212207
ids=[item.nodeid for item in session.items],
213208
)
214209

src/xdist/scheduler/load.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from itertools import cycle
22

3-
from _pytest.runner import CollectReport
3+
import pytest
44

55
from xdist.remote import Producer
66
from xdist.report import report_collection_diff
@@ -307,8 +307,11 @@ def _check_nodes_have_same_collection(self):
307307
same_collection = False
308308
self.log(msg)
309309
if self.config is not None:
310-
rep = CollectReport(
311-
node.gateway.id, "failed", longrepr=msg, result=[]
310+
rep = pytest.CollectReport(
311+
nodeid=node.gateway.id,
312+
outcome="failed",
313+
longrepr=msg,
314+
result=[],
312315
)
313316
self.config.hook.pytest_collectreport(report=rep)
314317

src/xdist/scheduler/loadscope.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import OrderedDict
22

3-
from _pytest.runner import CollectReport
3+
import pytest
44

55
from xdist.remote import Producer
66
from xdist.report import report_collection_diff
@@ -410,7 +410,12 @@ def _check_nodes_have_same_collection(self):
410410
if self.config is None:
411411
continue
412412

413-
rep = CollectReport(node.gateway.id, "failed", longrepr=msg, result=[])
413+
rep = pytest.CollectReport(
414+
nodeid=node.gateway.id,
415+
outcome="failed",
416+
longrepr=msg,
417+
result=[],
418+
)
414419
self.config.hook.pytest_collectreport(report=rep)
415420

416421
return same_collection

src/xdist/scheduler/worksteal.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any
44
from typing import NamedTuple
55

6-
from _pytest.runner import CollectReport
6+
import pytest
77

88
from xdist.remote import Producer
99
from xdist.report import report_collection_diff
@@ -323,8 +323,11 @@ def _check_nodes_have_same_collection(self):
323323
same_collection = False
324324
self.log(msg)
325325
if self.config is not None:
326-
rep = CollectReport(
327-
node.gateway.id, "failed", longrepr=msg, result=[]
326+
rep = pytest.CollectReport(
327+
nodeid=node.gateway.id,
328+
outcome="failed",
329+
longrepr=msg,
330+
result=[],
328331
)
329332
self.config.hook.pytest_collectreport(report=rep)
330333

src/xdist/workermanage.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,7 @@ def process_from_remote(self, eventcall):
401401
# should not land in receiver-thread
402402
raise
403403
except BaseException:
404-
from _pytest._code import ExceptionInfo
405-
406-
excinfo = ExceptionInfo.from_current()
404+
excinfo = pytest.ExceptionInfo.from_current()
407405
print("!" * 20, excinfo)
408406
self.config.notify_exception(excinfo)
409407
self.shutdown()

testing/acceptance_test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,14 +1112,11 @@ def test_error_report_styles():
11121112
result.assert_outcomes(failed=1)
11131113

11141114

1115-
def test_color_yes_collection_on_non_atty(pytester, request) -> None:
1115+
def test_color_yes_collection_on_non_atty(pytester) -> None:
11161116
"""Skip collect progress report when working on non-terminals.
11171117
11181118
Similar to pytest-dev/pytest#1397
11191119
"""
1120-
tr = request.config.pluginmanager.getplugin("terminalreporter")
1121-
if not hasattr(tr, "isatty"):
1122-
pytest.skip("only valid for newer pytest versions")
11231120
pytester.makepyfile(
11241121
"""
11251122
import pytest

testing/test_looponfail.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
from xdist.looponfail import StatRecorder
1313

1414

15-
PYTEST_GTE_7 = hasattr(pytest, "version_tuple") and pytest.version_tuple >= (7, 0) # type: ignore[attr-defined]
16-
17-
1815
class TestStatRecorder:
1916
def test_filechange(self, tmp_path: Path) -> None:
2017
tmp = tmp_path
@@ -128,9 +125,8 @@ def test_failures_somewhere(self, pytester: pytest.Pytester) -> None:
128125
failures = control.runsession()
129126
assert failures
130127
control.setup()
131-
item_path = item.path if PYTEST_GTE_7 else Path(str(item.fspath)) # type: ignore[attr-defined]
132-
item_path.write_text("def test_func():\n assert 1\n")
133-
removepyc(item_path)
128+
item.path.write_text("def test_func():\n assert 1\n")
129+
removepyc(item.path)
134130
topdir, failures = control.runsession()[:2]
135131
assert not failures
136132

@@ -146,10 +142,7 @@ def test_func():
146142
control = RemoteControl(modcol.config)
147143
control.loop_once()
148144
assert control.failures
149-
if PYTEST_GTE_7:
150-
modcol_path = modcol.path # type:ignore[attr-defined]
151-
else:
152-
modcol_path = Path(str(modcol.fspath))
145+
modcol_path = modcol.path # type:ignore[attr-defined]
153146

154147
modcol_path.write_text(
155148
textwrap.dedent(
@@ -179,10 +172,7 @@ def test_func():
179172
"""
180173
)
181174
)
182-
if PYTEST_GTE_7:
183-
parent = modcol.path.parent.parent # type: ignore[attr-defined]
184-
else:
185-
parent = Path(modcol.fspath.dirpath().dirpath())
175+
parent = modcol.path.parent.parent # type: ignore[attr-defined]
186176
monkeypatch.chdir(parent)
187177
modcol.config.args = [
188178
str(Path(x).relative_to(parent)) for x in modcol.config.args
@@ -248,8 +238,7 @@ def test_two():
248238
remotecontrol.loop_once()
249239
assert len(remotecontrol.failures) == 1
250240

251-
modcol_path = modcol.path if PYTEST_GTE_7 else Path(modcol.fspath)
252-
modcol_path.write_text(
241+
modcol.path.write_text(
253242
textwrap.dedent(
254243
"""
255244
def test_one():
@@ -259,7 +248,7 @@ def test_two():
259248
"""
260249
)
261250
)
262-
removepyc(modcol_path)
251+
removepyc(modcol.path)
263252
remotecontrol.loop_once()
264253
assert not remotecontrol.failures
265254

@@ -277,8 +266,7 @@ def test_one():
277266
assert len(remotecontrol.failures) == 1
278267
assert "test_one" in remotecontrol.failures[0]
279268

280-
modcol_path = modcol.path if PYTEST_GTE_7 else Path(modcol.fspath)
281-
modcol_path.write_text(
269+
modcol.path.write_text(
282270
textwrap.dedent(
283271
"""
284272
def test_one():
@@ -288,7 +276,7 @@ def test_two():
288276
"""
289277
)
290278
)
291-
removepyc(modcol_path)
279+
removepyc(modcol.path)
292280
remotecontrol.loop_once()
293281
assert len(remotecontrol.failures) == 0
294282
remotecontrol.loop_once()

testing/test_remote.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,7 @@ def test_mainargv(request):
338338
assert result.ret == 0
339339

340340

341-
def test_remote_usage_prog(pytester: pytest.Pytester, request) -> None:
342-
if not hasattr(request.config._parser, "prog"):
343-
pytest.skip("prog not available in config parser")
341+
def test_remote_usage_prog(pytester: pytest.Pytester) -> None:
344342
pytester.makeconftest(
345343
"""
346344
import pytest

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ isolated_build = true
99
[testenv]
1010
extras = testing
1111
deps =
12-
pytestmin: pytest==6.2.0
12+
pytestmin: pytest==7.0.0
1313
pytestlatest: pytest
1414
pytestmain: git+https://github.com/pytest-dev/pytest.git
1515
commands=

0 commit comments

Comments
 (0)