1
- import shutil
1
+ import tempfile
2
2
import textwrap
3
3
import os
4
4
import unittest
10
10
# mypy not installed on pypy (see setup.py)
11
11
mypy_installed = False
12
12
13
- HERE = os .path .dirname (__file__ )
14
- TEST_OUTPUT_DIR = os .path .join (HERE , "test-output" )
15
13
MYPY_INI = """\
16
14
[mypy]
17
15
follow_imports = silent
@@ -25,21 +23,17 @@ class TestMypyPlugin(unittest.TestCase):
25
23
26
24
def setUp (self ):
27
25
"""
28
- Prepare a clean test directory at tests/test-output/test_mypy-{testname} .
26
+ Prepare a clean temporary test directory.
29
27
Also cd into it for the duration of the test to get simple filenames in mypy output.
30
28
"""
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 ()
36
30
self .old_cwd = os .getcwd ()
37
31
os .chdir (self .testdir )
38
32
39
33
def tearDown (self ):
40
34
os .chdir (self .old_cwd )
41
35
42
- def mypy_test (self , contents : str , expected : str ):
36
+ def assert_mypy_output (self , contents : str , expected : str ):
43
37
"""
44
38
Run mypy and assert output matches ``expected``.
45
39
@@ -59,7 +53,7 @@ def mypy_test(self, contents: str, expected: str):
59
53
self .assertEqual (out .strip (), textwrap .dedent (expected ).strip (), err_msg )
60
54
61
55
def test_basic (self ):
62
- self .mypy_test (
56
+ self .assert_mypy_output (
63
57
"""
64
58
from dataclasses import dataclass
65
59
import marshmallow as ma
0 commit comments