@@ -133,6 +133,71 @@ def test_simple_discovery() -> None:
133
133
assert "error" not in actual
134
134
135
135
136
+ def test_simple_discovery_with_top_dir_calculated () -> None :
137
+ """The discover_tests function should return a dictionary with a "success" status, a uuid, no errors, and a test tree
138
+ if unittest discovery was performed successfully.
139
+ """
140
+ start_dir = "."
141
+ pattern = "discovery_simple*"
142
+ file_path = os .fsdecode (pathlib .PurePath (TEST_DATA_PATH / "discovery_simple.py" ))
143
+
144
+ expected = {
145
+ "path" : os .fsdecode (pathlib .PurePath (TEST_DATA_PATH )),
146
+ "type_" : TestNodeTypeEnum .folder ,
147
+ "name" : ".data" ,
148
+ "children" : [
149
+ {
150
+ "name" : "discovery_simple.py" ,
151
+ "type_" : TestNodeTypeEnum .file ,
152
+ "path" : file_path ,
153
+ "children" : [
154
+ {
155
+ "name" : "DiscoverySimple" ,
156
+ "path" : file_path ,
157
+ "type_" : TestNodeTypeEnum .class_ ,
158
+ "children" : [
159
+ {
160
+ "name" : "test_one" ,
161
+ "path" : file_path ,
162
+ "type_" : TestNodeTypeEnum .test ,
163
+ "lineno" : "14" ,
164
+ "id_" : file_path
165
+ + "\\ "
166
+ + "DiscoverySimple"
167
+ + "\\ "
168
+ + "test_one" ,
169
+ },
170
+ {
171
+ "name" : "test_two" ,
172
+ "path" : file_path ,
173
+ "type_" : TestNodeTypeEnum .test ,
174
+ "lineno" : "17" ,
175
+ "id_" : file_path
176
+ + "\\ "
177
+ + "DiscoverySimple"
178
+ + "\\ "
179
+ + "test_two" ,
180
+ },
181
+ ],
182
+ "id_" : file_path + "\\ " + "DiscoverySimple" ,
183
+ }
184
+ ],
185
+ "id_" : file_path ,
186
+ }
187
+ ],
188
+ "id_" : os .fsdecode (pathlib .PurePath (TEST_DATA_PATH )),
189
+ }
190
+
191
+ uuid = "some-uuid"
192
+ # Define the CWD to be the root of the test data folder.
193
+ os .chdir (os .fsdecode (pathlib .PurePath (TEST_DATA_PATH )))
194
+ actual = discover_tests (start_dir , pattern , None , uuid )
195
+
196
+ assert actual ["status" ] == "success"
197
+ assert is_same_tree (actual .get ("tests" ), expected )
198
+ assert "error" not in actual
199
+
200
+
136
201
def test_empty_discovery () -> None :
137
202
"""The discover_tests function should return a dictionary with a "success" status, a uuid, no errors, and no test tree
138
203
if unittest discovery was performed successfully but no tests were found.
0 commit comments