From 0dd0032a08231ed246caccfd6be4b7e82466fe51 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 8 Aug 2024 16:50:35 -0400 Subject: [PATCH] fix: allow pytest opts to be a string (#468) Signed-off-by: Henry Schreiner --- src/sp_repo_review/checks/pyproject.py | 5 +++- tests/test_pyproject.py | 32 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/sp_repo_review/checks/pyproject.py b/src/sp_repo_review/checks/pyproject.py index 607ebec5..b497a808 100644 --- a/src/sp_repo_review/checks/pyproject.py +++ b/src/sp_repo_review/checks/pyproject.py @@ -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): diff --git a/tests/test_pyproject.py b/tests/test_pyproject.py index 342e8e17..050ed9c5 100644 --- a/tests/test_pyproject.py +++ b/tests/test_pyproject.py @@ -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