2
2
# Licensed under the MIT License.
3
3
import os
4
4
import shutil
5
+ from typing import Any , Dict , List , Optional
5
6
6
7
import pytest
7
8
from tests .pytestadapter import expected_execution_test_output
@@ -13,7 +14,7 @@ def test_syntax_error_execution(tmp_path):
13
14
"""Test pytest execution on a file that has a syntax error.
14
15
15
16
Copies the contents of a .txt file to a .py file in the temporary directory
16
- to then run pytest exeuction on.
17
+ to then run pytest execution on.
17
18
18
19
The json should still be returned but the errors list should be present.
19
20
@@ -28,25 +29,29 @@ def test_syntax_error_execution(tmp_path):
28
29
temp_dir .mkdir ()
29
30
p = temp_dir / "error_syntax_discovery.py"
30
31
shutil .copyfile (file_path , p )
31
- actual = runner (["error_syntax_discover.py::test_function" ])
32
- assert actual
33
- assert all (item in actual for item in ("status" , "cwd" , "error" ))
34
- assert actual ["status" ] == "error"
35
- assert actual ["cwd" ] == os .fspath (TEST_DATA_PATH )
36
- assert len (actual ["error" ]) == 1
32
+ actual_list : Optional [List [Dict [str , Any ]]] = runner (
33
+ ["error_syntax_discover.py::test_function" ]
34
+ )
35
+ assert actual_list
36
+ for actual in actual_list :
37
+ assert all (item in actual for item in ("status" , "cwd" , "error" ))
38
+ assert actual ["status" ] == "error"
39
+ assert actual ["cwd" ] == os .fspath (TEST_DATA_PATH )
40
+ assert len (actual ["error" ]) == 1
37
41
38
42
39
43
def test_bad_id_error_execution ():
40
44
"""Test pytest discovery with a non-existent test_id.
41
45
42
46
The json should still be returned but the errors list should be present.
43
47
"""
44
- actual = runner (["not/a/real::test_id" ])
45
- assert actual
46
- assert all (item in actual for item in ("status" , "cwd" , "error" ))
47
- assert actual ["status" ] == "error"
48
- assert actual ["cwd" ] == os .fspath (TEST_DATA_PATH )
49
- assert len (actual ["error" ]) == 1
48
+ actual_list : Optional [List [Dict [str , Any ]]] = runner (["not/a/real::test_id" ])
49
+ assert actual_list
50
+ for actual in actual_list :
51
+ assert all (item in actual for item in ("status" , "cwd" , "error" ))
52
+ assert actual ["status" ] == "error"
53
+ assert actual ["cwd" ] == os .fspath (TEST_DATA_PATH )
54
+ assert len (actual ["error" ]) == 1
50
55
51
56
52
57
@pytest .mark .parametrize (
@@ -153,13 +158,14 @@ def test_pytest_execution(test_ids, expected_const):
153
158
expected_const -- a dictionary of the expected output from running pytest discovery on the files.
154
159
"""
155
160
args = test_ids
156
- actual = runner (args )
157
- assert actual
158
- assert all (item in actual for item in ("status" , "cwd" , "result" ))
159
- assert actual ["status" ] == "success"
160
- assert actual ["cwd" ] == os .fspath (TEST_DATA_PATH )
161
- result_data = actual ["result" ]
162
- for key in result_data :
163
- if result_data [key ]["outcome" ] == "failure" :
164
- result_data [key ]["message" ] = "ERROR MESSAGE"
165
- assert result_data == expected_const
161
+ actual_list : Optional [List [Dict [str , Any ]]] = runner (args )
162
+ assert actual_list
163
+ for actual in actual_list :
164
+ assert all (item in actual for item in ("status" , "cwd" , "result" ))
165
+ assert actual ["status" ] == "success"
166
+ assert actual ["cwd" ] == os .fspath (TEST_DATA_PATH )
167
+ result_data = actual ["result" ]
168
+ for key in result_data :
169
+ if result_data [key ]["outcome" ] == "failure" :
170
+ result_data [key ]["message" ] = "ERROR MESSAGE"
171
+ assert result_data == expected_const
0 commit comments