Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow pytest opts to be a string #468

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/sp_repo_review/checks/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ def check(pyproject: dict[str, Any]) -> bool:
```
"""
options = pyproject["tool"]["pytest"]["ini_options"]
return any(opt.startswith("-r") for opt in options.get("addopts", []))
addopts = options.get("addopts", [])
if isinstance(addopts, str):
addopts = addopts.split()
return any(opt.startswith("-r") for opt in addopts)


class PP309(PyProject):
Expand Down
32 changes: 32 additions & 0 deletions tests/test_pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,35 @@ def test_PP302_too_low():
minversion = "5"
""")
assert not compute_check("PP302", pyproject=toml).result


def test_PP308_list_okay():
toml = toml_loads("""
[tool.pytest.ini_options]
addopts = ["-ra"]
""")
assert compute_check("PP308", pyproject=toml).result


def test_PP308_list_missing():
toml = toml_loads("""
[tool.pytest.ini_options]
addopts = ["-otther"]
""")
assert not compute_check("PP308", pyproject=toml).result


def test_PP308_string_okay():
toml = toml_loads("""
[tool.pytest.ini_options]
addopts = "--stuff -ra --morestuff"
""")
assert compute_check("PP308", pyproject=toml).result


def test_PP308_string_missing():
toml = toml_loads("""
[tool.pytest.ini_options]
addopts = "--stuff --morestuff"
""")
assert not compute_check("PP308", pyproject=toml).result