2
2
# Licensed under the MIT License.
3
3
import os
4
4
import shutil
5
+ from typing import Any , Dict , List
5
6
6
7
import pytest
7
8
@@ -23,14 +24,19 @@ def test_config_file():
23
24
expected_execution_test_output .config_file_pytest_expected_execution_output
24
25
)
25
26
assert actual
26
- assert len (actual ) == len (expected_const )
27
+ actual_list : List [Dict [str , Any ]] = actual
28
+ assert actual_list .pop (- 1 ).get ("eot" )
29
+ assert len (actual_list ) == len (expected_const )
27
30
actual_result_dict = dict ()
28
- for a in actual :
29
- assert all (item in a for item in ("status" , "cwd" , "result" ))
30
- assert a ["status" ] == "success"
31
- assert a ["cwd" ] == os .fspath (new_cwd )
32
- actual_result_dict .update (a ["result" ])
33
- assert actual_result_dict == expected_const
31
+ if actual_list is not None :
32
+ for actual_item in actual_list :
33
+ assert all (
34
+ item in actual_item .keys () for item in ("status" , "cwd" , "result" )
35
+ )
36
+ assert actual_item .get ("status" ) == "success"
37
+ assert actual_item .get ("cwd" ) == os .fspath (new_cwd )
38
+ actual_result_dict .update (actual_item ["result" ])
39
+ assert actual_result_dict == expected_const
34
40
35
41
36
42
def test_rootdir_specified ():
@@ -43,14 +49,19 @@ def test_rootdir_specified():
43
49
expected_execution_test_output .config_file_pytest_expected_execution_output
44
50
)
45
51
assert actual
46
- assert len (actual ) == len (expected_const )
52
+ actual_list : List [Dict [str , Any ]] = actual
53
+ assert actual_list .pop (- 1 ).get ("eot" )
54
+ assert len (actual_list ) == len (expected_const )
47
55
actual_result_dict = dict ()
48
- for a in actual :
49
- assert all (item in a for item in ("status" , "cwd" , "result" ))
50
- assert a ["status" ] == "success"
51
- assert a ["cwd" ] == os .fspath (new_cwd )
52
- actual_result_dict .update (a ["result" ])
53
- assert actual_result_dict == expected_const
56
+ if actual_list is not None :
57
+ for actual_item in actual_list :
58
+ assert all (
59
+ item in actual_item .keys () for item in ("status" , "cwd" , "result" )
60
+ )
61
+ assert actual_item .get ("status" ) == "success"
62
+ assert actual_item .get ("cwd" ) == os .fspath (new_cwd )
63
+ actual_result_dict .update (actual_item ["result" ])
64
+ assert actual_result_dict == expected_const
54
65
55
66
56
67
def test_syntax_error_execution (tmp_path ):
@@ -73,13 +84,23 @@ def test_syntax_error_execution(tmp_path):
73
84
p = temp_dir / "error_syntax_discovery.py"
74
85
shutil .copyfile (file_path , p )
75
86
actual = runner (["error_syntax_discover.py::test_function" ])
76
- if actual :
77
- actual = actual [0 ]
78
- assert actual
79
- assert all (item in actual for item in ("status" , "cwd" , "error" ))
80
- assert actual ["status" ] == "error"
81
- assert actual ["cwd" ] == os .fspath (TEST_DATA_PATH )
82
- assert len (actual ["error" ]) == 1
87
+ assert actual
88
+ actual_list : List [Dict [str , Any ]] = actual
89
+ assert actual_list .pop (- 1 ).get ("eot" )
90
+ if actual_list is not None :
91
+ for actual_item in actual_list :
92
+ assert all (
93
+ item in actual_item .keys () for item in ("status" , "cwd" , "error" )
94
+ )
95
+ assert actual_item .get ("status" ) == "error"
96
+ assert actual_item .get ("cwd" ) == os .fspath (TEST_DATA_PATH )
97
+ error_content = actual_item .get ("error" )
98
+ if error_content is not None and isinstance (
99
+ error_content , (list , tuple , str )
100
+ ): # You can add other types if needed
101
+ assert len (error_content ) == 1
102
+ else :
103
+ assert False
83
104
84
105
85
106
def test_bad_id_error_execution ():
@@ -88,13 +109,23 @@ def test_bad_id_error_execution():
88
109
The json should still be returned but the errors list should be present.
89
110
"""
90
111
actual = runner (["not/a/real::test_id" ])
91
- if actual :
92
- actual = actual [0 ]
93
- assert actual
94
- assert all (item in actual for item in ("status" , "cwd" , "error" ))
95
- assert actual ["status" ] == "error"
96
- assert actual ["cwd" ] == os .fspath (TEST_DATA_PATH )
97
- assert len (actual ["error" ]) == 1
112
+ assert actual
113
+ actual_list : List [Dict [str , Any ]] = actual
114
+ assert actual_list .pop (- 1 ).get ("eot" )
115
+ if actual_list is not None :
116
+ for actual_item in actual_list :
117
+ assert all (
118
+ item in actual_item .keys () for item in ("status" , "cwd" , "error" )
119
+ )
120
+ assert actual_item .get ("status" ) == "error"
121
+ assert actual_item .get ("cwd" ) == os .fspath (TEST_DATA_PATH )
122
+ error_content = actual_item .get ("error" )
123
+ if error_content is not None and isinstance (
124
+ error_content , (list , tuple , str )
125
+ ): # You can add other types if needed
126
+ assert len (error_content ) == 1
127
+ else :
128
+ assert False
98
129
99
130
100
131
@pytest .mark .parametrize (
@@ -195,7 +226,8 @@ def test_pytest_execution(test_ids, expected_const):
195
226
3. uf_single_method_execution_expected_output: test run on a single method in a file.
196
227
4. uf_non_adjacent_tests_execution_expected_output: test run on unittests in two files with single selection in test explorer.
197
228
5. unit_pytest_same_file_execution_expected_output: test run on a file with both unittest and pytest tests.
198
- 6. dual_level_nested_folder_execution_expected_output: test run on a file with one test file at the top level and one test file in a nested folder.
229
+ 6. dual_level_nested_folder_execution_expected_output: test run on a file with one test file
230
+ at the top level and one test file in a nested folder.
199
231
7. double_nested_folder_expected_execution_output: test run on a double nested folder.
200
232
8. parametrize_tests_expected_execution_output: test run on a parametrize test with 3 inputs.
201
233
9. single_parametrize_tests_expected_execution_output: test run on single parametrize test.
@@ -205,18 +237,22 @@ def test_pytest_execution(test_ids, expected_const):
205
237
Keyword arguments:
206
238
test_ids -- an array of test_ids to run.
207
239
expected_const -- a dictionary of the expected output from running pytest discovery on the files.
208
- """ # noqa: E501
240
+ """
209
241
args = test_ids
210
242
actual = runner (args )
211
243
assert actual
212
- print (actual )
213
- assert len (actual ) == len (expected_const )
244
+ actual_list : List [Dict [str , Any ]] = actual
245
+ assert actual_list .pop (- 1 ).get ("eot" )
246
+ assert len (actual_list ) == len (expected_const )
214
247
actual_result_dict = dict ()
215
- for a in actual :
216
- assert all (item in a for item in ("status" , "cwd" , "result" ))
217
- assert a ["status" ] == "success"
218
- assert a ["cwd" ] == os .fspath (TEST_DATA_PATH )
219
- actual_result_dict .update (a ["result" ])
248
+ if actual_list is not None :
249
+ for actual_item in actual_list :
250
+ assert all (
251
+ item in actual_item .keys () for item in ("status" , "cwd" , "result" )
252
+ )
253
+ assert actual_item .get ("status" ) == "success"
254
+ assert actual_item .get ("cwd" ) == os .fspath (TEST_DATA_PATH )
255
+ actual_result_dict .update (actual_item ["result" ])
220
256
for key in actual_result_dict :
221
257
if (
222
258
actual_result_dict [key ]["outcome" ] == "failure"
0 commit comments