From ef7ac3a3ecd172aa822d22539ef314335e2b98f9 Mon Sep 17 00:00:00 2001 From: JsNcAr Date: Thu, 15 Oct 2026 10:48:58 -0500 Subject: [PATCH] ci: every warning is an error, and implicit encodings are warnings pytest.ini sets filterwarnings = error: a deprecation in this code or in a dependency fails the run instead of scrolling past in the summary. Both CI test jobs start the interpreter with -X warn_default_encoding, so a text read without an explicit encoding fails too. Set on the interpreter rather than in the job's env so Poetry's own process stays quiet. The suite was already clean under both flags with dependencies included (140 passed); a sanity test with a stray DeprecationWarning fails as intended. Co-Authored-By: Claude Fable 5.1 --- .github/workflows/ci.yml | 5 ++++- .gitlab-ci.yml | 3 ++- AGENTS.md | 4 +++- CHANGELOG.md | 6 ++++++ docs/setup.md | 12 ++++++++++-- pytest.ini | 7 +++++-- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4e3245..500a33d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,4 +87,7 @@ jobs: - name: Install the Poetry that wrote poetry.lock run: pip install "poetry==$(sed -n 's/.*generated by Poetry \([0-9.]*\).*/\1/p' poetry.lock | head -1)" - run: poetry install --no-interaction - - run: poetry run pytest + # -X warn_default_encoding: a text read without an explicit encoding is a + # warning, and pytest.ini turns warnings into errors. On the interpreter, + # not in the job's env, so Poetry's own process stays quiet. + - run: poetry run python -X warn_default_encoding -m pytest diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d7131d3..d7a5e5d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -100,7 +100,8 @@ test: # The PostgreSQL major the project targets; CI on GitHub tests the same one. - postgres:17 script: - - poetry run pytest --junitxml=report.xml + # -X warn_default_encoding: same as the GitHub job, see its comment. + - poetry run python -X warn_default_encoding -m pytest --junitxml=report.xml artifacts: when: always reports: diff --git a/AGENTS.md b/AGENTS.md index 37a71df..3b829c4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -54,7 +54,9 @@ docs/ # setup, authentication, api, schemas, releasing, known_issue ## Common Commands * **Start dev server**: `poetry run uvicorn basic_api.main:app --reload --app-dir src` * **Test**: `poetry run pytest` (needs PostgreSQL; `--noconftest` plus the pure - test files runs without one) + test files runs without one). Every warning is an error (`pytest.ini`); CI + adds `-X warn_default_encoding`, so run + `poetry run python -X warn_default_encoding -m pytest` before pushing. * **Format & lint**: `poetry run black src tests scripts && poetry run flake8 src tests scripts` * **Type check**: `poetry run mypy` (covers `src` and `scripts`) * **Release** (in a clone, never in the starter): `poetry run python scripts/release.py prepare minor`; diff --git a/CHANGELOG.md b/CHANGELOG.md index 586df59..e9f2efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,12 @@ notes (see [docs/releasing.md](docs/releasing.md)). `RequestBodyLimitMiddleware` answers 413 before any route runs (#13). ### Changed +- The test suite treats every warning as an error (`filterwarnings = error` + in `pytest.ini`), and both CI test jobs start the interpreter with + `-X warn_default_encoding`. A deprecation in this code or in a dependency, + or a text read without an explicit encoding, now fails CI instead of + scrolling past in the summary; the suite was already clean under both, with + dependencies included (#24). - Python 3.15 idioms. Read-only module constants are `frozendict` (`_SECRET_MINIMUM_BYTES`, `_TAKEN_MESSAGES`, `_DESCRIPTIONS`, the release script's `SECTIONS`); generic aliases come from `collections.abc` with the diff --git a/docs/setup.md b/docs/setup.md index 0683c48..2e815ef 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -113,8 +113,16 @@ poetry run pytest --noconftest tests/test_auth_units.py tests/test_user_schemas. tests/test_logging_config.py tests/test_request_id.py tests/test_release_script.py ``` -Deprecation warnings are not silenced; a new one in the summary is information, -not noise. +Every warning is an error (`filterwarnings = error` in `pytest.ini`): a +deprecation in this code or in a dependency fails the run instead of scrolling +past in the summary. Fix it, update the dependency, or record it in +[Known Issues](known_issues.md) with a narrow ignore. CI also starts the +interpreter with `-X warn_default_encoding`, so a text read without an explicit +encoding fails there; the same run locally is: + +```bash +poetry run python -X warn_default_encoding -m pytest +``` ## Code quality diff --git a/pytest.ini b/pytest.ini index d724d8e..ef5e3b7 100644 --- a/pytest.ini +++ b/pytest.ini @@ -4,7 +4,10 @@ addopts = -ra -q testpaths = tests pythonpath = src python_files = test_*.py -# No warning filters: a deprecation in our code or a dependency stays visible -# in the summary and is dealt with (or recorded in docs/known_issues.md). +# Every warning is an error: a deprecation in our code or in a dependency fails +# the run instead of scrolling past in the summary. Fix it, update the +# dependency, or record it in docs/known_issues.md with a narrow ignore below. +filterwarnings = + error asyncio_mode = auto asyncio_default_fixture_loop_scope = function