Skip to content

Commit

Permalink
Add pyproject toml to ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Oct 25, 2024
1 parent 2345435 commit 8c65e33
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ def pytest_runtestloop(session: Session) -> bool:
return True


def _is_setuptools_project(path: Path) -> bool:
"""Attempt to detect if ``path`` is the root of a setuptools project by
checking the existence of setup.py, setup.cfg, or pyproject.toml.
"""
indicators = ("setup.py", "setup.cfg", "pyproject.toml")
return any((path / f).exists() for f in indicators)


def _in_venv(path: Path) -> bool:
"""Attempt to detect if ``path`` is the root of a Virtual Environment by
checking for the existence of the pyvenv.cfg file.
Expand Down Expand Up @@ -422,8 +431,7 @@ def pytest_ignore_collect(collection_path: Path, config: Config) -> bool | None:
return True

if any(fnmatch_ex(pat, collection_path) for pat in ("build", "dist")):
parent = collection_path.parent
if (parent / "setup.py").exists() or (parent / "setup.cfg").exists():
if _is_setuptools_project(collection_path.parent):
return True

return None
Expand Down
15 changes: 14 additions & 1 deletion testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_build_dirs_collected(self, pytester: Pytester) -> None:
s = result.stdout.str()
assert "test_found" in s

def test_build_ignored_if_setuptools(self, pytester: Pytester) -> None:
def test_setuptools_ignored_if_present(self, pytester: Pytester) -> None:
tmp_path = pytester.path
ensure_file(tmp_path / "build" / "test_notfound.py")
ensure_file(tmp_path / "dist" / "test_notfound.py")
Expand All @@ -159,6 +159,19 @@ def test_build_ignored_if_setuptools(self, pytester: Pytester) -> None:
s = result.stdout.str()
assert "test_notfound" not in s

def test_setuptools_ignored_pyproject_toml(self, pytester: Pytester) -> None:
tmp_path = pytester.path
ensure_file(tmp_path / "build" / "test_notfound.py")
ensure_file(tmp_path / "dist" / "test_notfound.py")
for x in tmp_path.rglob("test_*.py"):
x.write_text("def test_hello(): pass", encoding="utf-8")

ensure_file(tmp_path / "pyproject.toml")

result = pytester.runpytest("--collect-only")
s = result.stdout.str()
assert "test_notfound" not in s

def test_ignored_certain_directories(self, pytester: Pytester) -> None:
tmp_path = pytester.path
ensure_file(tmp_path / "_darcs" / "test_notfound.py")
Expand Down

0 comments on commit 8c65e33

Please sign in to comment.