fix: add @pytest.mark.asyncio to async test methods (#21) #30
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-card-creation#30
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-card-creation#21"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #21
Summary
@pytest.mark.asyncioto all 14async deftest methods intests/test_automated_data_fetcher.pyFiles Changed
tests/test_automated_data_fetcher.py— 14 decorators addedTests
No test infrastructure to run. Changes verified by reading back the modified file: every
async def test_*method now has@pytest.mark.asyncioimmediately before it.Note:
pyproject.tomlalready hasasyncio_mode = "auto"which makes the marker optional at runtime, but adding it explicitly makes intent unambiguous and protects against future config changes.Other observations
tests/test_helpers.py:4-7(issue #16) has a related test quality problem worth addressing separately.Review: Non-standard decorator ordering on all 14 additions
The intent is correct — adding
@pytest.mark.asyncioprevents silent false-positive test passes ifasyncio_modeis ever changed from"auto". However, all 14 placements use non-standard ordering.Issue:
@pytest.mark.asyncioplaced below@patch(...)instead of above itThe standard convention (per pytest-asyncio docs) is for the asyncio marker to be the outermost decorator — topmost in the source:
Why it matters
With
asyncio_mode = "auto"(pyproject.toml:49) andunittest.mock.patch's use offunctools.wraps(which propagates__dict__includingpytestmark), the current ordering works at runtime. But:asyncio_modeis ever switched to"strict", whether the mark on the inner (unwrapped) function propagates through@patchwrappers is an implementation detail ofunittest.mock— not something to rely on.Fix
Move
@pytest.mark.asyncioto be the topmost decorator on all 14 methods. Mechanical change — just move each line above the@patch(...)stack.The core fix (adding the marker at all) is sound. Recommend correcting placement before merging.
AI Code Review
Files Reviewed
tests/test_automated_data_fetcher.py(modified)Findings
Correctness
All 14
async def test_*methods have been decorated. The count in the PR description is accurate. The change is mechanically correct — every async test method receives the marker.One nuance worth noting:
pyproject.tomlalready setsasyncio_mode = "auto", which causes pytest-asyncio to treat all async test functions as asyncio tests without needing the explicit decorator. The PR author is aware of this and calls it out clearly. The decorator is redundant at runtime but not harmful, and the stated rationale (explicit intent, resilience to future config changes) is sound.Decorator Ordering
In Python, decorators are applied from the bottom up (innermost first). The conventional placement for
@pytest.mark.asynciois above@patch(...)decorators so it is the outermost wrapper. In this PR,@pytest.mark.asynciois placed below@patchin every case — making it the innermost decorator. Example from the diff:With
asyncio_mode = "auto", this has no functional impact — pytest-asyncio handles the coroutine regardless of where the marker sits. However, ifasyncio_modewere ever removed or changed, this ordering would still work correctly because@pytest.mark.asynciojust needs to be present on the function object, not necessarily outermost. This is not a blocking issue.Security
No issues. This is a test-only change with no production code impact.
Style & Conventions
The project's CLAUDE.md specifies
pytestas the test runner andpytest-asyncio>=0.24.0is already a dev dependency. The change is consistent with those conventions. No issues.Suggestions
@pytest.mark.asyncioas the topmost decorator (above any@patchdecorators) for consistency with the broader pytest-asyncio community convention. This is purely stylistic givenasyncio_mode = "auto"is active.tests/test_helpers.py:4-7has a related test quality problem (issue #16). That is correctly deferred to a separate issue and does not affect this PR.Verdict: APPROVED
The change correctly adds
@pytest.mark.asyncioto all 14 async test methods, fixing the false-passing silently-skipped test problem described in issue #21. The decorator ordering is non-conventional but has no functional impact given theasyncio_mode = "auto"configuration already in place. No correctness, security, or convention violations that warrant blocking this merge.Automated review by Claude PR Reviewer
Approved for merge — correct fix, all async test methods now have @pytest.mark.asyncio.