Skip to content

Commit e11697e

Browse files
committed
Move pytest options to the pyproject.toml files
It is very difficult to change the options if they are shipped by repo-config, so it is better to put them in the template and leave users the flexibility to change them. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 37d223f commit e11697e

File tree

9 files changed

+42
-6
lines changed

9 files changed

+42
-6
lines changed

RELEASE_NOTES.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
9+
- The `nox` default `pytest` session doesn't pass `-W=all -vv` to `pytest` anymore. You can use the `pyproject.toml` file to configure default options for `pytest`, for example:
10+
11+
```toml
12+
[tool.pytest.ini_options]
13+
addopts = "-W=all -vv"
14+
```
1015

1116
### Cookiecutter template
1217

13-
<!-- Here upgrade steps for cookiecutter specifically -->
18+
All upgrading should be done via the migration script or regenerating the templates.
1419

1520
## New Features
1621

cookiecutter/migrate.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,38 @@
2929

3030
def main() -> None:
3131
"""Run the migration steps."""
32+
add_default_pytest_options()
33+
3234
# Add a separation line like this one after each migration step.
3335
print("=" * 72)
3436

3537

38+
def add_default_pytest_options() -> None:
39+
"""Add default pytest options to pyproject.toml."""
40+
pyproject_toml = Path("pyproject.toml")
41+
pyproject_toml_content = pyproject_toml.read_text(encoding="utf-8")
42+
marker = "[tool.pytest.ini_options]\n"
43+
new_options = "-W=all -vv"
44+
45+
print(f"Adding default pytest options to {pyproject_toml}...")
46+
if pyproject_toml_content.find(marker) == -1:
47+
print(
48+
"Couldn't find the the {marker.strip()} marker in pyproject.toml, skipping update."
49+
)
50+
return
51+
52+
if pyproject_toml_content.find("\naddopts") >= 0:
53+
print("It looks like some options are already configured, skipping update.")
54+
manual_step(f"Please consider `{new_options}` if they are not there yet.")
55+
return
56+
57+
replace_file_contents_atomically(
58+
pyproject_toml,
59+
marker,
60+
marker + f'addopts = "{new_options}"\n',
61+
)
62+
63+
3664
def apply_patch(patch_content: str) -> None:
3765
"""Apply a patch using the patch utility."""
3866
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)

cookiecutter/{{cookiecutter.github_repo_name}}/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ disable = [
203203

204204
[tool.pytest.ini_options]
205205
{%- if cookiecutter.type != "api" %}
206+
addopts = "-W=all -vv"
206207
testpaths = ["tests", "src"]
207208
asyncio_mode = "auto"
208209
asyncio_default_fixture_loop_scope = "function"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ module = [
205205
ignore_missing_imports = true
206206

207207
[tool.pytest.ini_options]
208+
addopts = "-W=all -vv"
208209
testpaths = ["src", "tests"]
209210
markers = [
210211
"integration: integration tests (deselect with '-m \"not integration\"')",

src/frequenz/repo/config/nox/default.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@
3636
"--check",
3737
],
3838
mypy=[],
39-
pytest=[
40-
"-W=all",
41-
"-vv",
42-
],
39+
pytest=[],
4340
)
4441
"""Default command-line options for all types of repositories."""
4542

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ disable = [
153153
]
154154

155155
[tool.pytest.ini_options]
156+
addopts = "-W=all -vv"
156157
testpaths = ["tests", "src"]
157158
asyncio_mode = "auto"
158159
asyncio_default_fixture_loop_scope = "function"

tests_golden/integration/test_cookiecutter_generation/app/frequenz-app-test/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ disable = [
152152
]
153153

154154
[tool.pytest.ini_options]
155+
addopts = "-W=all -vv"
155156
testpaths = ["tests", "src"]
156157
asyncio_mode = "auto"
157158
asyncio_default_fixture_loop_scope = "function"

tests_golden/integration/test_cookiecutter_generation/lib/frequenz-test-python/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ disable = [
149149
]
150150

151151
[tool.pytest.ini_options]
152+
addopts = "-W=all -vv"
152153
testpaths = ["tests", "src"]
153154
asyncio_mode = "auto"
154155
asyncio_default_fixture_loop_scope = "function"

tests_golden/integration/test_cookiecutter_generation/model/frequenz-model-test/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ disable = [
153153
]
154154

155155
[tool.pytest.ini_options]
156+
addopts = "-W=all -vv"
156157
testpaths = ["tests", "src"]
157158
asyncio_mode = "auto"
158159
asyncio_default_fixture_loop_scope = "function"

0 commit comments

Comments
 (0)