Skip to content

Commit 2bd6ebb

Browse files
committed
use tempfile instead of custom test-output
1 parent 2326e4d commit 2bd6ebb

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Auto-generated from tests
2-
test-output
3-
41
# Byte-compiled / optimized / DLL files
52
__pycache__/
63
*.py[cod]

tests/test_mypy.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import shutil
2+
import tempfile
23
import textwrap
34
import os
45
import unittest
@@ -10,8 +11,6 @@
1011
# mypy not installed on pypy (see setup.py)
1112
mypy_installed = False
1213

13-
HERE = os.path.dirname(__file__)
14-
TEST_OUTPUT_DIR = os.path.join(HERE, "test-output")
1514
MYPY_INI = """\
1615
[mypy]
1716
follow_imports = silent
@@ -25,21 +24,17 @@ class TestMypyPlugin(unittest.TestCase):
2524

2625
def setUp(self):
2726
"""
28-
Prepare a clean test directory at tests/test-output/test_mypy-{testname}.
27+
Prepare a clean temporary test directory.
2928
Also cd into it for the duration of the test to get simple filenames in mypy output.
3029
"""
31-
testname = self.id().split(".")[-1]
32-
self.testdir = os.path.join(TEST_OUTPUT_DIR, f"test_mypy-{testname}")
33-
if os.path.exists(self.testdir):
34-
shutil.rmtree(self.testdir)
35-
os.makedirs(self.testdir)
30+
self.testdir = tempfile.mkdtemp()
3631
self.old_cwd = os.getcwd()
3732
os.chdir(self.testdir)
3833

3934
def tearDown(self):
4035
os.chdir(self.old_cwd)
4136

42-
def mypy_test(self, contents: str, expected: str):
37+
def assert_mypy_output(self, contents: str, expected: str):
4338
"""
4439
Run mypy and assert output matches ``expected``.
4540
@@ -59,7 +54,7 @@ def mypy_test(self, contents: str, expected: str):
5954
self.assertEqual(out.strip(), textwrap.dedent(expected).strip(), err_msg)
6055

6156
def test_basic(self):
62-
self.mypy_test(
57+
self.assert_mypy_output(
6358
"""
6459
from dataclasses import dataclass
6560
import marshmallow as ma

0 commit comments

Comments
 (0)