Skip to content

Testing third-party stubs in isolated environments #5952

Closed

Description

@srittau

At the moment, whenever there is change to typeshed, we test all stdlib and third-party packages in the same testing environment, using the --custom-typeshed-dir so that all packages can see each other. There are several practical problems with that:

My suggestion: Only run the tests for the third-party stubs that have actually changed, and run each test in a separate environment. This environment only has the requirements from METADATA.toml installed. This fixes the problems above and also means:

  • The stubs will not be able to use features from stdlib that are not yet in the latest type checker distributions.
  • Changes that depend on changes in another third-party stub need to wait until that change has been released. (Happens every three hours, so it shouldn't be too much of a problem.)
  • Running the tests for all stubs will be slower, since each package needs its own venv installation.

Activity

  1. Akuli commented on Aug 23, 2021

    @Akuli
    Collaborator

    A possible downside: If the tests of a third-party stub break for some reason, e.g. because a new version of the corresponding non-stub package is released, the problem will remain unnoticed until someone makes a PR for that specific stub package. I remember most pull requests showing red CI because of some Pillow thing, but can't find it from the PR history now.

  2. srittau commented on Aug 23, 2021

    @srittau
    CollaboratorAuthor

    It would be useful to run full tests at a regular interval, say once per day or week.

  3. hauntsaninja commented on Aug 23, 2021

    @hauntsaninja
    Collaborator

    Note the stubtest third party code already does this venv creation. We could steal that code / maybe use some fancy Github Actions CI caching to cache venvs across workflows. Switching to testing only changed third party stubs is probably a better idea than just doing everything and sharding, which is the approach test_stubtest currently takes.

    Like you say, I'd want to think through how we manage different stdlib and types-* versions; to that goal, here are some previous issues we've had on those lines: #4815 #5786 #5751

  4. Akuli commented on Dec 5, 2021

    @Akuli
    Collaborator

    This seems to be done now.

  5. srittau commented on Dec 6, 2021

    @srittau
    CollaboratorAuthor

    No, we still need to use separate venvs for each distribution, so that the dependencies don't interfere with each other.

  6. reopened this on Dec 6, 2021
  7. added and removed
    project: policyOrganization of the typeshed project
    on Jan 17, 2022
  8. hmc-cs-mdrissi commented on Feb 20, 2022

    @hmc-cs-mdrissi
    Contributor

    I would be interested in working on this mainly to make it possible to have non-types dependencies.

    Would reasonable steps in order be,

    1. Adjust each check to only run for changed folders. Start with mypy then continue to pyright then pytype.
    2. Create a new venv for each folder checked. Again mypy -> pyright -> pytype
    3. Add support for reading metadata.toml and install dependencies for given folder.
    4. Add support for per package mypy.ini/pyrightconfig.json/etc files.

    Any major tasks I'm missing?

  9. hauntsaninja commented on Feb 20, 2022

    @hauntsaninja
    Collaborator

    That sounds reasonable. Some thoughts:

    • It might make sense to split each test up into running on the stdlib vs running on individual third party distributions (like we do with stubtest)
    • Here's some code for venv creation:
      with tempfile.TemporaryDirectory() as tmp:
    • We'd want to make sure that other stubs don't interfere, e.g. we should not be picking up cryptography-stubs if someone declares a cryptography dep. The various type checkers probably each handle this differently
    • We talked about only having a small, vetted list of deps. If this is the case, I personally wouldn't hate getting started on Allow non-types dependencies #5768 with a global venv. This might be controversial though :-)
    • It might be nice to use different keys in pyproject.toml for typeshed deps vs other deps (e.g., could make automation in the future easier / avoid mistakes where we assume that "types-*" packages are trusted). Might need a change in https://github.com/typeshed-internal/stub_uploader
    • There's an @tests folder you can reuse for per-distribution config files. We even store some extra requirements.txt's in there
  10. srittau commented on Feb 21, 2022

    @srittau
    CollaboratorAuthor

    @hmc-cs-mdrissi For now you could try to skip step 1 and we can see how that affects CI runtimes.

  11. changed the title [-]Testing third-party stubs[/-] [+]Testing third-party stubs in isolated environments[/+] on Jun 18, 2022
  12. AlexWaygood commented on Jan 8, 2023

    @AlexWaygood
    Member

    As of #9408, third-party stubs with non-types dependencies are now tested with mypy in isolated venvs. The venvs are setup concurrently using a threadpool, meaning we still test all typeshed stubs packages in every run, but the script remains performant.

    (Stubs packages with no non-types dependencies are not tested in a separate venv, but they are tested using the --no-site-packages flag when they are tested, so are still run in an isolated environment.)

    Closing as completed! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions