Skip to content

Commit

Permalink
fix: pytest 8 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare committed Mar 4, 2024
1 parent 37b8e73 commit d488950
Showing 1 changed file with 27 additions and 8 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

Check warning on line 39 in pytest_ruff/__init__.py

View check run for this annotation

Codecov / codecov/patch

pytest_ruff/__init__.py#L39

Added line #L39 was not covered by tests

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

Check warning on line 51 in pytest_ruff/__init__.py

View check run for this annotation

Codecov / codecov/patch

pytest_ruff/__init__.py#L51

Added line #L51 was not covered by tests

if path.ext != ".py":
return

Check warning on line 54 in pytest_ruff/__init__.py

View check run for this annotation

Codecov / codecov/patch

pytest_ruff/__init__.py#L54

Added line #L54 was not covered by tests

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

0 comments on commit d488950

Please sign in to comment.