Skip to content

Commit

Permalink
testupdatedata: fix cwd (#15383)
Browse files Browse the repository at this point in the history
This should allow the inner pytest to pass even when the outer pytest is
invoked outside of the mypy root, e.g.
```shell
cd ..
pytest mypy/mypy/test/testupdatedata.py
```

Addresses
#15283 (comment).
  • Loading branch information
ikonst authored Jun 6, 2023
1 parent 66bd2c4 commit 8409b88
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mypy/test/testupdatedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def _run_pytest_update_data(self, data_suite: str, *, max_attempts: int) -> str:
Runs a suite of data test cases through 'pytest --update-data' until either tests pass
or until a maximum number of attempts (needed for incremental tests).
"""
p = Path(test_data_prefix) / "check-update-data.test"
p_test_data = Path(test_data_prefix)
p_root = p_test_data.parent.parent
p = p_test_data / "check-update-data.test"
assert not p.exists()
try:
p.write_text(textwrap.dedent(data_suite).lstrip())
Expand All @@ -26,7 +28,7 @@ def _run_pytest_update_data(self, data_suite: str, *, max_attempts: int) -> str:
else:
cmd = " ".join(args)
for i in range(max_attempts - 1, -1, -1):
res = subprocess.run(args)
res = subprocess.run(args, cwd=p_root)
if res.returncode == 0:
break
print(f"`{cmd}` returned {res.returncode}: {i} attempts remaining")
Expand Down

0 comments on commit 8409b88

Please sign in to comment.