pytest-mypy-testing
pytest-mypy-testing copied to clipboard
ref: Run mypy once and collate messages per-file
This PR does the following:
- It collects all of the
PytestMypyFileat initialization into an object that can run mypy on all files at once. This eliminates duplication of effort that scales with the number of files that any tests exist in. The output messages are collated by file and queried as needed. - I removed
"--no-silence-site-packages",from the mypy args. This drops the runtime on my test data from ~360s to ~35s from an empty cache. - Uses pytest's
config.cacheto store amypy-cacheinside.pytest_cache/d/. I have verified that it works to construct a new cache even usingpytest-xdistwhere mypy tests ended up on multiple cores. Looks like mypy takes care of multiple processes updating a cache simultaneously. Pytest can be run with--cache-clearto manually clear the cache. This brings us from ~35s on the first run to ~1s on subsequent runs. Updating my source code invalidates the cache, but reruns take ~17s. - Removes unused components of
MypyResult. This was mainly because it was simpler to do the rest once I knew what was never read. Those could be restored, but there would at least no longer be a coupling between returncode and the specific file being read, as an error in one file would produce a nonzero returncode for all files.
If you're interested, I'm happy to clean this up with any adjustments you'd like. I can also break it up into one PR for each of the above points, if you'd rather consider one thing at a time.
Closes #13.