Skip to content

Support async tests decorated with override_config - #676

Merged
Mogost merged 3 commits into
django-commons:masterfrom
jihtsan:codex/522-async-override
Oct 28, 2026
Merged

Mogost merged 3 commits into
django-commons:masterfrom
jihtsan:codex/522-async-override

Conversation

@jihtsan

@jihtsan jihtsan commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Keep override_config-decorated coroutine functions recognizable as async tests and retain overrides until the awaited function finishes. Run synchronous override setup/cleanup in a thread-sensitive worker so the database backend remains usable; always restore values when the test raises. Synchronous functions and class decoration keep the existing path.

Closes #522.

Validation on CPython 3.13.12 / Django 5.2.18: new regressions fail on the original wrapper, then cover coroutine identity, values across suspension, return values, exception restoration, direct async test methods and a real SQLite backend. Full unittest run passes (169 tests, 1 intentional skip); full pytest passes (176 passed, 1 skipped, 6 existing sync-access warnings). CI-pinned Ruff 0.5.0 lint/format checks pass on both changed Python files; migration check reports no changes. The full unittest suite also passes on CPython 3.11.16 / Django 4.2.30 (169 tests, 1 intentional skip). Other matrix combinations and hosted CI were not verified. Redis tests use the repository mock; no real Redis server was used. Documentation text was checked but not built locally.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cancellation during setup can skip cleanup while the worker still applies overrides, leaking configuration into subsequent tests.

1 open issue
What changed in this PR

Adds async support to override_config, addressing #522 by preserving coroutine detection and keeping overrides active until the awaited test finishes.

Changes:

  • Adds an async wrapper with thread-sensitive setup and cleanup, while preserving synchronous and class decoration.
  • Adds regressions for coroutine detection, override lifetime, return values, exception restoration, and database-backed usage.
  • Documents async test support.
File Description
tests/​test_test_overrides.py Adds async decorator regressions, including database backend coverage.
docs/​testing.rst Documents override lifetime for async tests.
constance/​test/​unittest.py Adds coroutine-aware wrapping with worker-thread setup and cleanup.

Review effort: Balanced

Comment thread constance/test/unittest.py Resolved
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
constance/test/unittest.py 89.28% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Mogost and others added 2 commits October 28, 2026 11:35
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Mogost
Mogost merged commit 580667c into django-commons:master Oct 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@override_config decorator RuntimeWarning wih async test

4 participants