Skip to content

ref: Run mypy once and collate messages per-file #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

effigies
Copy link

@effigies effigies commented Jan 25, 2025

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.

Comment on lines +57 to +58
if have_xdist:
self.add_marker(pytest.mark.xdist_group("mypy"))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done separately, but targets the same overall goal of running mypy once. Without this, pytest-xdist could potentially build a mypy cache for every worker. This puts all mypy jobs on the same worker (provided the user passes --dist loadgroup to pytest), so only one cache is built.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reusing cache during rapid iterations
1 participant