Skip to content

Commit

Permalink
fix: pytest 8.1 compat (#16)
Browse files Browse the repository at this point in the history
* fix: pytest 8 compat

* Test on yanked pytest 8.1.0

---------

Co-authored-by: Iuri de Silvio <iurisilvio@gmail.com>
  • Loading branch information
hairmare and iurisilvio authored Mar 10, 2024
1 parent 41ec4c4 commit 9efc242
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
35 changes: 27 additions & 8 deletions pytest_ruff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}

Expand Down

0 comments on commit 9efc242

Please sign in to comment.