Skip to content

Single threaded pytest spuriously fails for testcmdline and testpythoneval #4127

@elazarg

Description

@elazarg

Reported by @gvanrossum in #3870 :

Sadly there's a problem with this. When I run the tests as follows:

pytest -n0 mypy/test/testcmdline.py

every test in that file fails. Apparently the pytest-xdist extension which runs tests in parallel does something that keeps the tests from failing. The error is essentially that every subprocess invoking scripts/mypy fails with the following traceback:

 Traceback (most recent call last):
   File "/Users/guido/src/mypy/scripts/mypy", line 4, in <module>
     from mypy.main import main
 ModuleNotFoundError: No module named 'mypy.main'

This makes sense as the current directory is set to the temporary directory where the test files are written, so the repo root is not on sys.path. I'm guessing that the xdist extension somehow retains the current directory?

The pythoneval tests fail in the same way.

(End quote)

On my machine most of the tests pass, except testCoberturaParser:

Expected:
  <coverage timestamp="$TIMESTAMP" version="$VERSION" line-rate="0.8000" branch-rate="0"> (diff)
  ...
Actual:
  <coverage timestamp="$TIMESTAMP" version="0.530" line-rate="0.8000" branch-rate="0"> (diff)
  ...

Apparently pytest-xdist adds mypy's base dir to PYTHONPATH.

This issue has two items:

  • Fix the failures
  • Add tests to prevent the reintroduction of such failures

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions