Skip to content

Commit f3f7f5a

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

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
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-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import shutil
1+
import tempfile
22
import textwrap
33
import os
44
import unittest
@@ -10,8 +10,6 @@
1010
# mypy not installed on pypy (see setup.py)
1111
mypy_installed = False
1212

13-
HERE = os.path.dirname(__file__)
14-
TEST_OUTPUT_DIR = os.path.join(HERE, "test-output")
1513
MYPY_INI = """\
1614
[mypy]
1715
follow_imports = silent
@@ -25,21 +23,17 @@ class TestMypyPlugin(unittest.TestCase):
2523

2624
def setUp(self):
2725
"""
28-
Prepare a clean test directory at tests/test-output/test_mypy-{testname}.
26+
Prepare a clean temporary test directory.
2927
Also cd into it for the duration of the test to get simple filenames in mypy output.
3028
"""
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)
29+
self.testdir = tempfile.mkdtemp()
3630
self.old_cwd = os.getcwd()
3731
os.chdir(self.testdir)
3832

3933
def tearDown(self):
4034
os.chdir(self.old_cwd)
4135

42-
def mypy_test(self, contents: str, expected: str):
36+
def assert_mypy_output(self, contents: str, expected: str):
4337
"""
4438
Run mypy and assert output matches ``expected``.
4539
@@ -59,7 +53,7 @@ def mypy_test(self, contents: str, expected: str):
5953
self.assertEqual(out.strip(), textwrap.dedent(expected).strip(), err_msg)
6054

6155
def test_basic(self):
62-
self.mypy_test(
56+
self.assert_mypy_output(
6357
"""
6458
from dataclasses import dataclass
6559
import marshmallow as ma

0 commit comments

Comments
 (0)