pytest-mypy-testing icon indicating copy to clipboard operation
pytest-mypy-testing copied to clipboard

ref: Run mypy once and collate messages per-file

Open effigies opened this issue 11 months ago • 0 comments

This PR does the following:

  1. It collects all of the PytestMypyFile at 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.
  2. 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.
  3. Uses pytest's config.cache to store a mypy-cache inside .pytest_cache/d/. I have verified that it works to construct a new cache even using pytest-xdist where 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-clear to 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.
  4. 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.

effigies avatar Jan 25 '25 17:01 effigies