Skip to content
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

stubtest: Fix wrong assumption about relative path #12282

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@


@contextlib.contextmanager
def use_tmp_dir() -> Iterator[None]:
def use_tmp_dir(mod_name: str) -> Iterator[None]:
current = os.getcwd()
current_syspath = sys.path[:]
with tempfile.TemporaryDirectory() as tmp:
try:
os.chdir(tmp)
if sys.path[0] != tmp:
sys.path.insert(0, tmp)
yield
finally:
sys.path = current_syspath[:]
if mod_name in sys.modules:
del sys.modules[mod_name]

os.chdir(current)


Expand Down Expand Up @@ -92,7 +99,7 @@ def staticmethod(f: T) -> T: ...
def run_stubtest(
stub: str, runtime: str, options: List[str], config_file: Optional[str] = None,
) -> str:
with use_tmp_dir():
with use_tmp_dir(TEST_MODULE_NAME):
with open("builtins.pyi", "w") as f:
f.write(stubtest_builtins_stub)
with open("typing.pyi", "w") as f:
Expand All @@ -105,11 +112,6 @@ def run_stubtest(
with open("{}_config.ini".format(TEST_MODULE_NAME), "w") as f:
f.write(config_file)
options = options + ["--mypy-config-file", "{}_config.ini".format(TEST_MODULE_NAME)]
if sys.path[0] != ".":
sys.path.insert(0, ".")
if TEST_MODULE_NAME in sys.modules:
del sys.modules[TEST_MODULE_NAME]

output = io.StringIO()
with contextlib.redirect_stdout(output):
test_stubs(
Expand Down
4 changes: 2 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ flake8-pyi>=20.5
lxml>=4.4.0; python_version<'3.11'
psutil>=4.0
# pytest 6.2.3 does not support Python 3.10
pytest>=6.2.4,<7.0.0
pytest-xdist>=1.34.0,<2.0.0
pytest>=6.2.4
pytest-xdist>=1.34.0
pytest-forked>=1.3.0,<2.0.0
pytest-cov>=2.10.0,<3.0.0
py>=1.5.2
Expand Down