From 9efc242a519f8c7648bc732a170079864b592521 Mon Sep 17 00:00:00 2001 From: Lucas Bickel <116588+hairmare@users.noreply.github.com> Date: Sun, 10 Mar 2024 13:47:41 +0100 Subject: [PATCH] fix: pytest 8.1 compat (#16) * fix: pytest 8 compat * Test on yanked pytest 8.1.0 --------- Co-authored-by: Iuri de Silvio --- pytest_ruff/__init__.py | 35 +++++++++++++++++++++++++++-------- tox.ini | 7 +++++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/pytest_ruff/__init__.py b/pytest_ruff/__init__.py index dea76a7..eade02c 100644 --- a/pytest_ruff/__init__.py +++ b/pytest_ruff/__init__.py @@ -4,7 +4,12 @@ from ruff.__main__ import find_ruff_bin -from pytest_ruff._pytest_compat import get_stash, make_path_kwargs, set_stash +from pytest_ruff._pytest_compat import ( + get_stash, + make_path_kwargs, + set_stash, + PYTEST_VER, +) HISTKEY = "ruff/mtimes" @@ -26,15 +31,29 @@ def pytest_configure(config): set_stash(config, config.cache.get(HISTKEY, {})) -def pytest_collect_file(path, parent, fspath=None): - config = parent.config - if not config.option.ruff: - return +if PYTEST_VER >= (7, 0): - if path.ext != ".py": - return + def pytest_collect_file(file_path, parent, fspath=None): + config = parent.config + if not config.option.ruff: + return + + if file_path.suffix != ".py": + return + + return RuffFile.from_parent(parent, **make_path_kwargs(file_path)) + +else: + + def pytest_collect_file(path, parent, fspath=None): + config = parent.config + if not config.option.ruff: + return + + if path.ext != ".py": + return - return RuffFile.from_parent(parent, **make_path_kwargs(path)) + return RuffFile.from_parent(parent, **make_path_kwargs(path)) def pytest_sessionfinish(session, exitstatus): diff --git a/tox.ini b/tox.ini index fcbc6d6..6c5de3c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] isolated_build = true -envlist = py{38,39,310,311,312}-pytest{5,6,7,8},lint +envlist = py{38,39,310,311,312}-pytest{5,6,7,8,810,81},lint [testenv] allowlist_externals = poetry @@ -9,7 +9,10 @@ commands = pytest5: pip install "pytest<6" pytest6: pip install "pytest>=6,<7" pytest7: pip install "pytest>=7,<8" - pytest8: pip install "pytest>=8,<9" + pytest8: pip install "pytest>=8,<8.1" + # pytest 8.1.0 was yanked, but their "broken behaviour" will comeback soon + pytest810: pip install "pytest==8.1.0" + pytest81: pip install "pytest>=8.1,<9" # Disable ruff plugin to generate better coverage results poetry run pytest -p no:ruff -vvv --cov --cov-append --cov-report term --cov-report xml {posargs}