Repository navigation
Fix cross-test mypy cache contamination - #3299
Merged
UnknownPlatypus merged 1 commit intoApr 15, 2026
Merged
Conversation
Member
Do you have any ideas? |
Contributor
Author
I don't know where it appens but we would need to make sure the temporary fiels crated in tests contain a hash or the test case name |
Member
|
Using test case name as a folder for temp files - sounds like a good idea! PR is welcome :) |
UnknownPlatypus
added a commit
to UnknownPlatypus/pytest-mypy-plugins
that referenced
this pull request
Apr 13, 2026
The old cleanup removed individual cache files per test file path. This was insufficient because: 1. It only removed cache entries for exact files listed in the test, missing entries auto-generated by mypy or plugins (e.g. Django plugin injecting cross-app model dependencies). 2. It only handled the legacy JSON file-based cache, not the SQLite cache.db format used by mypy >= 1.14. The new cleanup collects top-level module/package names from the test's files and removes ALL cache entries under those names, using both the SQLite database and legacy JSON file cleanup paths. This prevents sequential cache contamination within a single pytest-xdist worker when consecutive tests define modules with the same name (e.g. "myapp") but different internal structures. Fixes typeddjango/django-stubs#3299
UnknownPlatypus
added a commit
to UnknownPlatypus/pytest-mypy-plugins
that referenced
this pull request
Apr 13, 2026
mypy >= 1.14 changed its incremental cache from .data.json/.meta.json files to .data.ff/.meta.ff/.err.ff files. The cleanup code only knew about the old .json suffixes, so it silently removed nothing, leaving stale cache entries that contaminated subsequent tests sharing the same module names (e.g. "myapp"). Add the modern .ff suffixes to the cleanup loop. Fixes typeddjango/django-stubs#3299
Contributor
Author
|
The issue was with the new style of mypy cache actually, cf typeddjango/pytest-mypy-plugins#186 |
UnknownPlatypus
force-pushed
the
fix/per-test-mypy-cache
branch
from
April 14, 2026 16:40
96c8c67 to
051dc2b
Compare
UnknownPlatypus
marked this pull request as ready for review
April 14, 2026 16:49
Contributor
Author
|
@sobolevn I've updated the pr description with details, seem to work nicely for me |
sobolevn
approved these changes
Apr 15, 2026
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.
I have made things!
Prior to this change, I was having the
models_triple_circular_referencetest always failing when running the full test suite withpytest -n autowhile it was passing in isolation.The issue was with pytest-mypy-plugin that was not handling correctly new mypy cache format.
The fix is to pull typeddjango/pytest-mypy-plugins#186
This is slightly slower but is expected since previously we were not doing any cache cleanup because of the bug.
I can confirm that it fixes
pytest -n auto locallyOutdated investigation
Use a unique cache directory per test instead of per worker to prevent stale module entries from contaminating subsequent tests that reuse module names like "myapp".
Marking as draft for now to check if the performance impact is ok or notThe performance hit is too high (2x slower), I can fix the offending test by renaming the app but it seem brittle. Should something be patched in pytest-mypy-plugin @sobolevn ?
AI Policy