Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@

## Upgrading

<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
- 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:

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

### Cookiecutter template

<!-- Here upgrade steps for cookiecutter specifically -->
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
31 changes: 31 additions & 0 deletions cookiecutter/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,41 @@

def main() -> None:
"""Run the migration steps."""
add_default_pytest_options()

# Add a separation line like this one after each migration step.
print("=" * 72)


def add_default_pytest_options() -> None:
"""Add default pytest options to pyproject.toml."""
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 Werror -Wdefault::DeprecationWarning "
"-Wdefault::PendingDeprecationWarning -vv"
)

print(f"Adding default pytest options to {pyproject_toml}...")
if pyproject_toml_content.find(marker) == -1:
print(
"Couldn't find the the {marker.strip()} marker in pyproject.toml, skipping update."
)
return

if pyproject_toml_content.find("\naddopts") >= 0:
print("It looks like some options are already configured, skipping update.")
manual_step(f"Please consider `{new_options}` if they are not there yet.")
return

replace_file_contents_atomically(
pyproject_toml,
marker,
marker + f'addopts = "{new_options}"\n',
)


def apply_patch(patch_content: str) -> None:
"""Apply a patch using the patch utility."""
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ disable = [

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

[tool.pytest.ini_options]
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -vv"
testpaths = ["src", "tests"]
markers = [
"integration: integration tests (deselect with '-m \"not integration\"')",
Expand Down
5 changes: 1 addition & 4 deletions src/frequenz/repo/config/nox/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
"--check",
],
mypy=[],
pytest=[
"-W=all",
"-vv",
],
pytest=[],
)
"""Default command-line options for all types of repositories."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ disable = [
]

[tool.pytest.ini_options]
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -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,6 +152,7 @@ disable = [
]

[tool.pytest.ini_options]
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -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,6 +149,7 @@ disable = [
]

[tool.pytest.ini_options]
addopts = "-W=all -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning -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,6 +153,7 @@ disable = [
]

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