Skip to content

Commit 47b0143

Browse files
committed
Treat pytest warnings as errors
Warnings are usually a sign of something that can be improved or even wrong, like tasks not being properly awaited or cancelled, so it's a good idea to treat them as errors to avoid them getting unnoticed. We still treat deprecations as warnings, as when testing with the `pytest_min` session is normal to get deprecation warnings as we are using old versions of dependencies. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent e11697e commit 47b0143

File tree

8 files changed

+15
-10
lines changed

8 files changed

+15
-10
lines changed

RELEASE_NOTES.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010

1111
```toml
1212
[tool.pytest.ini_options]
13-
addopts = "-W=all -vv"
13+
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
1414
```
1515

1616
### Cookiecutter template
1717

18-
All upgrading should be done via the migration script or regenerating the templates.
18+
All upgrading should be done via the migration script or regenerating the templates. But you might still need to adapt your code:
19+
20+
- `pytest` now uses `-Werror` by default (but still treat deprecations as normal warnings), so if your tests run with warnings, they will now be turned to errors, and you'll need to fix them.
1921

2022
## New Features
2123

2224
<!-- Here goes the main new features and examples or instructions on how to use them -->
2325

2426
### Cookiecutter template
2527

26-
<!-- Here new features for cookiecutter specifically -->
28+
- `pytest` now uses `-Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning` by default. Deprecations are still treated as warnings, as when testing with the `pytest_min` session is normal to get deprecation warnings as we are using old versions of dependencies.
2729

2830
## Bug Fixes
2931

cookiecutter/migrate.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def add_default_pytest_options() -> None:
4040
pyproject_toml = Path("pyproject.toml")
4141
pyproject_toml_content = pyproject_toml.read_text(encoding="utf-8")
4242
marker = "[tool.pytest.ini_options]\n"
43-
new_options = "-W=all -vv"
43+
new_options = (
44+
"-W=all Werror -Wdefault::DeprecationWarning "
45+
"-Wdefault::PendingDeprecationWarning -vv"
46+
)
4447

4548
print(f"Adding default pytest options to {pyproject_toml}...")
4649
if pyproject_toml_content.find(marker) == -1:

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ disable = [
203203

204204
[tool.pytest.ini_options]
205205
{%- if cookiecutter.type != "api" %}
206-
addopts = "-W=all -vv"
206+
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
207207
testpaths = ["tests", "src"]
208208
asyncio_mode = "auto"
209209
asyncio_default_fixture_loop_scope = "function"

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ module = [
205205
ignore_missing_imports = true
206206

207207
[tool.pytest.ini_options]
208-
addopts = "-W=all -vv"
208+
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
209209
testpaths = ["src", "tests"]
210210
markers = [
211211
"integration: integration tests (deselect with '-m \"not integration\"')",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ disable = [
153153
]
154154

155155
[tool.pytest.ini_options]
156-
addopts = "-W=all -vv"
156+
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
157157
testpaths = ["tests", "src"]
158158
asyncio_mode = "auto"
159159
asyncio_default_fixture_loop_scope = "function"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ disable = [
152152
]
153153

154154
[tool.pytest.ini_options]
155-
addopts = "-W=all -vv"
155+
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
156156
testpaths = ["tests", "src"]
157157
asyncio_mode = "auto"
158158
asyncio_default_fixture_loop_scope = "function"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ disable = [
149149
]
150150

151151
[tool.pytest.ini_options]
152-
addopts = "-W=all -vv"
152+
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
153153
testpaths = ["tests", "src"]
154154
asyncio_mode = "auto"
155155
asyncio_default_fixture_loop_scope = "function"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ disable = [
153153
]
154154

155155
[tool.pytest.ini_options]
156-
addopts = "-W=all -vv"
156+
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
157157
testpaths = ["tests", "src"]
158158
asyncio_mode = "auto"
159159
asyncio_default_fixture_loop_scope = "function"

0 commit comments

Comments
 (0)