@@ -290,7 +290,7 @@ def build_test_tree(session: pytest.Session) -> TestNode:
290
290
# parameterized test cases cut the repetitive part of the name off.
291
291
name_split = test_node ["name" ].split ("[" )
292
292
test_node ["name" ] = "[" + name_split [1 ]
293
- parent_path = os .fspath (test_case . path ) + "::" + name_split [0 ]
293
+ parent_path = os .fspath (get_node_path ( test_case ) ) + "::" + name_split [0 ]
294
294
try :
295
295
function_name = test_case .originalname # type: ignore
296
296
function_test_case = function_nodes_dict [parent_path ]
@@ -303,7 +303,7 @@ def build_test_tree(session: pytest.Session) -> TestNode:
303
303
)
304
304
except KeyError :
305
305
function_test_case : TestNode = create_parameterized_function_node (
306
- function_name , test_case . path , test_case .nodeid
306
+ function_name , get_node_path ( test_case ) , test_case .nodeid
307
307
)
308
308
function_nodes_dict [parent_path ] = function_test_case
309
309
function_test_case ["children" ].append (test_node )
@@ -354,7 +354,7 @@ def build_nested_folders(
354
354
355
355
# Begin the iterator_path one level above the current file.
356
356
iterator_path = file_node ["path" ].parent
357
- while iterator_path != session . path :
357
+ while iterator_path != get_node_path ( session ) :
358
358
curr_folder_name = iterator_path .name
359
359
try :
360
360
curr_folder_node : TestNode = created_files_folders_dict [
@@ -385,7 +385,7 @@ def create_test_node(
385
385
)
386
386
return {
387
387
"name" : test_case .name ,
388
- "path" : test_case . path ,
388
+ "path" : get_node_path ( test_case ) ,
389
389
"lineno" : test_case_loc ,
390
390
"type_" : "test" ,
391
391
"id_" : test_case .nodeid ,
@@ -399,13 +399,13 @@ def create_session_node(session: pytest.Session) -> TestNode:
399
399
Keyword arguments:
400
400
session -- the pytest session.
401
401
"""
402
- session_path = session . path if session . path else pathlib . Path . cwd ( )
402
+ node_path = get_node_path ( session )
403
403
return {
404
404
"name" : session .name ,
405
- "path" : session_path ,
405
+ "path" : node_path ,
406
406
"type_" : "folder" ,
407
407
"children" : [],
408
- "id_" : os .fspath (session . path ),
408
+ "id_" : os .fspath (node_path ),
409
409
}
410
410
411
411
@@ -417,7 +417,7 @@ def create_class_node(class_module: pytest.Class) -> TestNode:
417
417
"""
418
418
return {
419
419
"name" : class_module .name ,
420
- "path" : class_module . path ,
420
+ "path" : get_node_path ( class_module ) ,
421
421
"type_" : "class" ,
422
422
"children" : [],
423
423
"id_" : class_module .nodeid ,
@@ -451,11 +451,12 @@ def create_file_node(file_module: Any) -> TestNode:
451
451
Keyword arguments:
452
452
file_module -- the pytest file module.
453
453
"""
454
+ node_path = get_node_path (file_module )
454
455
return {
455
- "name" : file_module . path .name ,
456
- "path" : file_module . path ,
456
+ "name" : node_path .name ,
457
+ "path" : node_path ,
457
458
"type_" : "file" ,
458
- "id_" : os .fspath (file_module . path ),
459
+ "id_" : os .fspath (node_path ),
459
460
"children" : [],
460
461
}
461
462
@@ -497,6 +498,10 @@ class ExecutionPayloadDict(Dict):
497
498
error : Union [str , None ] # Currently unused need to check
498
499
499
500
501
+ def get_node_path (node : Any ) -> pathlib .Path :
502
+ return getattr (node , "path" , pathlib .Path (node .fspath ))
503
+
504
+
500
505
def execution_post (
501
506
cwd : str ,
502
507
status : Literal ["success" , "error" ],
0 commit comments