Skip to content

Commit 9729636

Browse files
committed
bah, win32 and its exclusive opens
1 parent f528cef commit 9729636

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

mypy/test/testupdatedata.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import subprocess
33
import sys
44
import textwrap
5-
from os.path import basename
6-
from tempfile import NamedTemporaryFile
5+
from pathlib import Path
76

87
from mypy.test.config import test_data_prefix
98
from mypy.test.helpers import Suite
@@ -13,14 +12,14 @@ class UpdateDataSuite(Suite):
1312
def _run_pytest_update_data(self, data_suite: str, *, max_attempts: int) -> str:
1413
"""
1514
Runs a suite of data test cases through 'pytest --update-data' until either tests pass
16-
or until a maximum number of attempts. (Multiple attempts can be needed for incremental tests.)
15+
or until a maximum number of attempts (needed for incremental tests).
1716
"""
18-
with NamedTemporaryFile(
19-
mode="w+", dir=test_data_prefix, prefix="check-update-data-", suffix=".test"
20-
) as tmp_file:
21-
tmp_file.write(textwrap.dedent(data_suite).lstrip())
22-
tmp_file.flush()
23-
test_nodeid = f"mypy/test/testcheck.py::TypeCheckSuite::{basename(tmp_file.name)}"
17+
p = Path(test_data_prefix) / "check-update-data.test"
18+
assert not p.exists()
19+
try:
20+
p.write_text(textwrap.dedent(data_suite).lstrip())
21+
22+
test_nodeid = f"mypy/test/testcheck.py::TypeCheckSuite::{p.name}"
2423
args = [sys.executable, "-m", "pytest", "-n", "0", "-s", "--update-data", test_nodeid]
2524
if sys.version_info >= (3, 8):
2625
cmd = shlex.join(args)
@@ -31,8 +30,10 @@ def _run_pytest_update_data(self, data_suite: str, *, max_attempts: int) -> str:
3130
if res.returncode == 0:
3231
break
3332
print(f"`{cmd}` returned {res.returncode}: {i} attempts remaining")
34-
tmp_file.seek(0)
35-
return tmp_file.read()
33+
34+
return p.read_text()
35+
finally:
36+
p.unlink()
3637

3738
def test_update_data(self) -> None:
3839
# Note: We test multiple testcases rather than 'test case per test case'

0 commit comments

Comments
 (0)