12
12
13
13
from . import expected_discovery_test_output , helpers # noqa: E402
14
14
15
- def test_import_error (tmp_path ):
15
+
16
+ def test_import_error ():
16
17
"""Test pytest discovery on a file that has a pytest marker but does not import pytest.
17
18
18
19
Copies the contents of a .txt file to a .py file in the temporary directory
@@ -23,15 +24,10 @@ def test_import_error(tmp_path):
23
24
Keyword arguments:
24
25
tmp_path -- pytest fixture that creates a temporary directory.
25
26
"""
26
- # Saving some files as .txt to avoid that file displaying a syntax error for
27
- # the extension as a whole. Instead, rename it before running this test
28
- # in order to test the error handling.
29
27
file_path = helpers .TEST_DATA_PATH / "error_pytest_import.txt"
30
- temp_dir = tmp_path / "temp_data"
31
- temp_dir .mkdir ()
32
- p = temp_dir / "error_pytest_import.py"
33
- shutil .copyfile (file_path , p )
34
- actual : Optional [List [Dict [str , Any ]]] = helpers .runner (["--collect-only" , os .fspath (p )])
28
+ with helpers .text_to_python_file (file_path ) as p :
29
+ actual : Optional [List [Dict [str , Any ]]] = helpers .runner (["--collect-only" , os .fspath (p )])
30
+
35
31
assert actual
36
32
actual_list : List [Dict [str , Any ]] = actual
37
33
if actual_list is not None :
@@ -65,11 +61,9 @@ def test_syntax_error(tmp_path):
65
61
# the extension as a whole. Instead, rename it before running this test
66
62
# in order to test the error handling.
67
63
file_path = helpers .TEST_DATA_PATH / "error_syntax_discovery.txt"
68
- temp_dir = tmp_path / "temp_data"
69
- temp_dir .mkdir ()
70
- p = temp_dir / "error_syntax_discovery.py"
71
- shutil .copyfile (file_path , p )
72
- actual = helpers .runner (["--collect-only" , os .fspath (p )])
64
+ with helpers .text_to_python_file (file_path ) as p :
65
+ actual = helpers .runner (["--collect-only" , os .fspath (p )])
66
+
73
67
assert actual
74
68
actual_list : List [Dict [str , Any ]] = actual
75
69
if actual_list is not None :
0 commit comments