Skip to content

Commit

Permalink
fix: allow pytest opts to be a string (#468)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Aug 8, 2024
1 parent 4249a57 commit 0dd0032
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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

0 comments on commit 0dd0032

Please sign in to comment.