Skip to content

Commit

Permalink
FIX: support newlines in pytest options
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Jan 11, 2024
1 parent 95827f3 commit eb99478
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/repoma/check_dev_files/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _update_settings() -> None:
return
config = get_sub_table(pyproject, "tool.pytest.ini_options")
addopts: str = config.get("addopts", "")

Check warning on line 79 in src/repoma/check_dev_files/pytest.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/pytest.py#L77-L79

Added lines #L77 - L79 were not covered by tests
options = {opt.strip() for opt in addopts.split()}
options = {opt.strip() for opt in __split_options(addopts)}
options = {opt for opt in options if opt and not opt.startswith("--color=")}
options.add("--color=yes")

Check warning on line 82 in src/repoma/check_dev_files/pytest.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/pytest.py#L82

Added line #L82 was not covered by tests
if len(options) == 1:
Expand All @@ -91,3 +91,19 @@ def _update_settings() -> None:
write_pyproject(pyproject)
msg = f"Updated tool.pytest.ini_options.addopts under {CONFIG_PATH.pyproject}"
raise PrecommitError(msg)

Check warning on line 93 in src/repoma/check_dev_files/pytest.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/pytest.py#L90-L93

Added lines #L90 - L93 were not covered by tests


def __split_options(string: str) -> list[str]:
"""Split a string of options into a list of options.
>>> __split_options('-abc def -ghi "j k l" -mno pqr')
['-abc def', '-ghi "j k l"', '-mno pqr']
"""
elements = string.split()
options: list[str] = []
for i in range(len(elements)):
if i > 0 and not elements[i].startswith("-"):
options[-1] += f" {elements[i]}"
else:
options.append(elements[i])
return options

0 comments on commit eb99478

Please sign in to comment.