Skip to content

Commit

Permalink
Treat pytest warnings as errors
Browse files Browse the repository at this point in the history
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 <luca-frequenz@llucax.com>
  • Loading branch information
llucax committed Nov 22, 2024
1 parent e11697e commit 26137c8
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@

```toml
[tool.pytest.ini_options]
addopts = "-W=all -vv"
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
```

### Cookiecutter template

All upgrading should be done via the migration script or regenerating the templates.
All upgrading should be done via the migration script or regenerating the templates. But you might still need to adapt your code:

- `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.

## New Features

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

### Cookiecutter template

<!-- Here new features for cookiecutter specifically -->
- `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.

## Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion cookiecutter/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def add_default_pytest_options() -> None:
pyproject_toml = Path("pyproject.toml")
pyproject_toml_content = pyproject_toml.read_text(encoding="utf-8")
marker = "[tool.pytest.ini_options]\n"
new_options = "-W=all -vv"
new_options = "-W=all Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"

print(f"Adding default pytest options to {pyproject_toml}...")
if pyproject_toml_content.find(marker) == -1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ disable = [

[tool.pytest.ini_options]
{%- if cookiecutter.type != "api" %}
addopts = "-W=all -vv"
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
testpaths = ["tests", "src"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ module = [
ignore_missing_imports = true

[tool.pytest.ini_options]
addopts = "-W=all -vv"
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
testpaths = ["src", "tests"]
markers = [
"integration: integration tests (deselect with '-m \"not integration\"')",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ disable = [
]

[tool.pytest.ini_options]
addopts = "-W=all -vv"
addopts = "-W=all -Werror -vv"
testpaths = ["tests", "src"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ disable = [
]

[tool.pytest.ini_options]
addopts = "-W=all -vv"
addopts = "-W=all -Werror -vv"
testpaths = ["tests", "src"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ disable = [
]

[tool.pytest.ini_options]
addopts = "-W=all -vv"
addopts = "-W=all -Werror -vv"
testpaths = ["tests", "src"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ disable = [
]

[tool.pytest.ini_options]
addopts = "-W=all -vv"
addopts = "-W=all -Werror -vv"
testpaths = ["tests", "src"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
Expand Down

0 comments on commit 26137c8

Please sign in to comment.