diff --git a/pytest_isort/__init__.py b/pytest_isort/__init__.py index e15ebad..1512bda 100644 --- a/pytest_isort/__init__.py +++ b/pytest_isort/__init__.py @@ -71,11 +71,21 @@ def _make_path_kwargs(p): return dict(path=Path(p)) if PYTEST_VER >= (7, 0) else dict(fspath=p) -def pytest_collect_file(path, parent): - config = parent.config - if config.option.isort and path.ext == '.py': - if not config._isort_ignore(path): - return IsortFile.from_parent(parent, **_make_path_kwargs(path)) +if PYTEST_VER >= (7, 0): + + def pytest_collect_file(file_path, parent): + config = parent.config + if config.option.isort and file_path.suffix == '.py': + if not config._isort_ignore(file_path): + return IsortFile.from_parent(parent, **_make_path_kwargs(file_path)) + +else: + + def pytest_collect_file(path, parent): + config = parent.config + if config.option.isort and path.ext == '.py': + if not config._isort_ignore(path): + return IsortFile.from_parent(parent, **_make_path_kwargs(path)) def pytest_sessionfinish(session): @@ -139,8 +149,12 @@ def __call__(self, path): """ for glob in self.ignores: - if path.fnmatch(glob): - return glob + if isinstance(path, Path): + if path.match(glob): + return glob + else: + if path.fnmatch(glob): + return glob return False diff --git a/tox.ini b/tox.ini index 470bb98..df7fc6a 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ isolated_build = true envlist = {py38,py39}-{pytest5,pytest6,pytest7}-{isort4,isort5} - {py310,py311}-{pytest6,pytest7}-{isort4,isort5} + {py310,py311}-{pytest6,pytest7,pytest8}-{isort4,isort5} [gh-actions] python = @@ -17,6 +17,7 @@ deps = pytest5: pytest>=5,<6 pytest6: pytest>=6,<7 pytest7: pytest>=7,<8 + pytest8: pytest>=8,<9 isort4: isort>=4,<5 isort5: isort>=5,<6 allowlist_externals =