Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45a5cf3

Browse files
authored
tests: Automatically run from source-tree root; and use default temp dir (#3426)
Several bits of our test runner system assume that the current working directory when tests are run is the root of the mypy source tree. This is a fine constraint to require, but the way we fail if that constraint is broken is an error in each test case's setup, which pytest presents as one of those massive stack traces it specializes in. See #3412. These dependencies include the way we find a temporary directory to use, and something to do with some imports. For the tempdir, just use `tempfile` in the usual default way -- as a bonus, we no longer need to stick temporary files under the source tree. The import issues seem like bugs, but rather than chase down that kind of bug in the test harness, just take care of the working directory automatically.
1 parent 71efcdb commit 45a5cf3

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import os.path
2+
3+
import pytest
4+
15
pytest_plugins = [
26
'mypy.test.data',
37
]
8+
9+
def pytest_configure(config):
10+
mypy_source_root = os.path.dirname(os.path.abspath(__file__))
11+
if os.getcwd() != mypy_source_root:
12+
os.chdir(mypy_source_root)

mypy/myunit/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ def run(self) -> None:
120120

121121
def set_up(self) -> None:
122122
self.old_cwd = os.getcwd()
123-
self.tmpdir = tempfile.TemporaryDirectory(prefix='mypy-test-',
124-
dir=os.path.abspath('tmp-test-dirs'))
123+
self.tmpdir = tempfile.TemporaryDirectory(prefix='mypy-test-')
125124
os.chdir(self.tmpdir.name)
126125
os.mkdir('tmp')
127126
if self.suite:

0 commit comments

Comments
 (0)