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