Skip to content

Commit 9efc242

Browse files
hairmareiurisilvio
andauthored
fix: pytest 8.1 compat (#16)
* fix: pytest 8 compat * Test on yanked pytest 8.1.0 --------- Co-authored-by: Iuri de Silvio <iurisilvio@gmail.com>
1 parent 41ec4c4 commit 9efc242

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

pytest_ruff/__init__.py

+27-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
from ruff.__main__ import find_ruff_bin
66

7-
from pytest_ruff._pytest_compat import get_stash, make_path_kwargs, set_stash
7+
from pytest_ruff._pytest_compat import (
8+
get_stash,
9+
make_path_kwargs,
10+
set_stash,
11+
PYTEST_VER,
12+
)
813

914
HISTKEY = "ruff/mtimes"
1015

@@ -26,15 +31,29 @@ def pytest_configure(config):
2631
set_stash(config, config.cache.get(HISTKEY, {}))
2732

2833

29-
def pytest_collect_file(path, parent, fspath=None):
30-
config = parent.config
31-
if not config.option.ruff:
32-
return
34+
if PYTEST_VER >= (7, 0):
3335

34-
if path.ext != ".py":
35-
return
36+
def pytest_collect_file(file_path, parent, fspath=None):
37+
config = parent.config
38+
if not config.option.ruff:
39+
return
40+
41+
if file_path.suffix != ".py":
42+
return
43+
44+
return RuffFile.from_parent(parent, **make_path_kwargs(file_path))
45+
46+
else:
47+
48+
def pytest_collect_file(path, parent, fspath=None):
49+
config = parent.config
50+
if not config.option.ruff:
51+
return
52+
53+
if path.ext != ".py":
54+
return
3655

37-
return RuffFile.from_parent(parent, **make_path_kwargs(path))
56+
return RuffFile.from_parent(parent, **make_path_kwargs(path))
3857

3958

4059
def pytest_sessionfinish(session, exitstatus):

tox.ini

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
isolated_build = true
3-
envlist = py{38,39,310,311,312}-pytest{5,6,7,8},lint
3+
envlist = py{38,39,310,311,312}-pytest{5,6,7,8,810,81},lint
44

55
[testenv]
66
allowlist_externals = poetry
@@ -9,7 +9,10 @@ commands =
99
pytest5: pip install "pytest<6"
1010
pytest6: pip install "pytest>=6,<7"
1111
pytest7: pip install "pytest>=7,<8"
12-
pytest8: pip install "pytest>=8,<9"
12+
pytest8: pip install "pytest>=8,<8.1"
13+
# pytest 8.1.0 was yanked, but their "broken behaviour" will comeback soon
14+
pytest810: pip install "pytest==8.1.0"
15+
pytest81: pip install "pytest>=8.1,<9"
1316
# Disable ruff plugin to generate better coverage results
1417
poetry run pytest -p no:ruff -vvv --cov --cov-append --cov-report term --cov-report xml {posargs}
1518

0 commit comments

Comments
 (0)