Repository navigation
Add assert_task_count() and an isolated-queue pytest recipe - #157
Merged
Merged
Conversation
django_ox.testing gains assert_task_count(). It reads OxTask rows for one backend alias, queue and task path and counts those whose stored args and kwargs equal the caller's after the JSON round trip enqueue() applies before storing them, so a tuple in args matches a stored list. A value the standard library's json.dumps() cannot handle, such as a raw datetime, UUID or Decimal, is rejected with TypeError naming the offending field rather than silently mismatching. A count that differs raises AssertionError naming the backend, queue, path, the args and kwargs after that round trip, and the expected and observed counts. The helper reads live rows, so a rolled-back enqueue is not counted. docs/patterns.md has two new sections. "Assert on the queue directly" documents the helper with a short example. "An isolated queue for one test" documents a pytest fixture recipe that wraps run_tasks() to drain a single reserved queue, and refuses with ValueError at fixture setup, before the test body enqueues anything, if that queue is already occupied by setUpTestData or an earlier fixture. The snippet says where the reserved name belongs: in that backend's own QUEUES list in the TASKS setting, a sibling of OPTIONS rather than a key inside it. The recipe is documentation, not a shipped API: tests/settings.py reserves the isolated-recipe queue in the test backend's QUEUES for it. docs/stability.md lists django_ox.testing.assert_task_count among the public testing helpers. It is public and stable: its keyword-only signature (path, queue, count, backend, args, kwargs) does not carry the provisional status run_tasks() has on that page. tests/test_testing_assertions.py, with its tasks in tests/testing_assertions_tasks.py, covers the helper and the recipe: JSON matching and rejection, backend and queue scoping, a finished row still counted, the count mismatch message, and the occupied-queue refusal. The tests run under both TestCase and TransactionTestCase. TestCase wraps every test in a transaction it rolls back, so the TransactionTestCase tests are the ones that read a row enqueue() has committed, and they also show that a nested atomic() which rolls back is still excluded without that outer transaction. CHANGELOG.md gets an Added entry under Unreleased and docs/llms-full.txt is regenerated. Closes #129
PhiLily
force-pushed
the
feature/run-tasks-assertions
branch
from
October 28, 2026 09:09
3f23e18 to
2d81a78
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
django_ox.testinggainsassert_task_count(). It readsOxTaskrows for one backend alias, queue and task path and counts those whose stored args and kwargs equal the caller's after the JSON round tripenqueue()applies before storing them, so a tuple in args matches a stored list. A value the standard library'sjson.dumps()cannot handle, such as a rawdatetime,UUIDorDecimal, is rejected withTypeErrornaming the offending field rather than silently mismatching. A count that differs raisesAssertionErrornaming the backend, queue, path, the args and kwargs after that round trip, and the expected and observed counts. The helper reads live rows, so a rolled-back enqueue is not counted.docs/patterns.mdhas two new sections. "Assert on the queue directly" documents the helper with a short example. "An isolated queue for one test" documents a pytest fixture recipe that wrapsrun_tasks()to drain a single reserved queue, and refuses withValueErrorat fixture setup, before the test body enqueues anything, if that queue is already occupied bysetUpTestDataor an earlier fixture. The recipe is documentation, not a shipped API:tests/settings.pyreserves theisolated-recipequeue in the test backend'sQUEUESfor it, andtests/test_testing_assertions.pycovers both the helper and the recipe, including JSON matching and rejection, backend and queue scoping, and the occupied-queue refusal.CHANGELOG.mdgets an Added entry anddocs/llms-full.txtis regenerated.The new test module and the full suite pass locally on SQLite;
ruff check,ruff format --check,mypy --strict src/andmkdocs build --strictpass on the branch.Closes #129