16
16
sys .path .append (os .fspath (script_dir / "lib" / "python" ))
17
17
18
18
from testing_tools import socket_manager # noqa: E402
19
- from typing import Any , Dict , Generator , List , Optional , Union , TypedDict , Literal # noqa: E402
19
+ from typing import ( # noqa: E402
20
+ Any ,
21
+ Dict ,
22
+ Generator ,
23
+ List ,
24
+ Optional ,
25
+ Union ,
26
+ TypedDict ,
27
+ Literal ,
28
+ )
20
29
21
30
22
31
class TestData (TypedDict ):
@@ -89,7 +98,9 @@ def pytest_load_initial_conftests(early_config, parser, args):
89
98
f"Plugin info[vscode-pytest]: rootdir argument, { rootdir } , is identified as a symlink."
90
99
)
91
100
elif pathlib .Path (os .path .realpath (rootdir )) != rootdir :
92
- print ("Plugin info[vscode-pytest]: Checking if rootdir is a child of a symlink." )
101
+ print (
102
+ "Plugin info[vscode-pytest]: Checking if rootdir is a child of a symlink."
103
+ )
93
104
isSymlink = has_symlink_parent (rootdir )
94
105
if isSymlink :
95
106
print (
@@ -125,9 +136,13 @@ def pytest_exception_interact(node, call, report):
125
136
if call .excinfo and call .excinfo .typename != "AssertionError" :
126
137
if report .outcome == "skipped" and "SkipTest" in str (call ):
127
138
return
128
- ERRORS .append (call .excinfo .exconly () + "\n Check Python Test Logs for more details." )
139
+ ERRORS .append (
140
+ call .excinfo .exconly () + "\n Check Python Test Logs for more details."
141
+ )
129
142
else :
130
- ERRORS .append (report .longreprtext + "\n Check Python Test Logs for more details." )
143
+ ERRORS .append (
144
+ report .longreprtext + "\n Check Python Test Logs for more details."
145
+ )
131
146
else :
132
147
# If during execution, send this data that the given node failed.
133
148
report_value = "error"
@@ -448,9 +463,13 @@ def build_test_tree(session: pytest.Session) -> TestNode:
448
463
".py" , 1
449
464
) # splits the file path from the rest of the nodeid
450
465
451
- class_and_method = second_split [1 ] + "::" # This has "::" separator at both ends
466
+ class_and_method = (
467
+ second_split [1 ] + "::"
468
+ ) # This has "::" separator at both ends
452
469
# construct the parent id, so it is absolute path :: any class and method :: parent_part
453
- parent_id = os .fspath (get_node_path (test_case )) + class_and_method + parent_part
470
+ parent_id = (
471
+ os .fspath (get_node_path (test_case )) + class_and_method + parent_part
472
+ )
454
473
# file, middle, param = test_case.nodeid.rsplit("::", 2)
455
474
# parent_id = test_case.nodeid.rsplit("::", 1)[0] + "::" + parent_part
456
475
# parent_path = os.fspath(get_node_path(test_case)) + "::" + parent_part
@@ -461,7 +480,9 @@ def build_test_tree(session: pytest.Session) -> TestNode:
461
480
ERRORS .append (
462
481
f"unable to find original name for { test_case .name } with parameterization detected."
463
482
)
464
- raise VSCodePytestError ("Unable to find original name for parameterized test case" )
483
+ raise VSCodePytestError (
484
+ "Unable to find original name for parameterized test case"
485
+ )
465
486
except KeyError :
466
487
function_test_node : TestNode = create_parameterized_function_node (
467
488
function_name , get_node_path (test_case ), parent_id
@@ -510,7 +531,10 @@ def build_test_tree(session: pytest.Session) -> TestNode:
510
531
test_file_node = create_file_node (parent_module )
511
532
file_nodes_dict [parent_module ] = test_file_node
512
533
# Check if the class is already a child of the file node.
513
- if test_class_node is not None and test_class_node not in test_file_node ["children" ]:
534
+ if (
535
+ test_class_node is not None
536
+ and test_class_node not in test_file_node ["children" ]
537
+ ):
514
538
test_file_node ["children" ].append (test_class_node )
515
539
elif not hasattr (test_case , "callspec" ):
516
540
# This includes test cases that are pytest functions or a doctests.
@@ -533,7 +557,9 @@ def build_test_tree(session: pytest.Session) -> TestNode:
533
557
print (
534
558
"[vscode-pytest]: Session path not a parent of test paths, adjusting session node to common parent."
535
559
)
536
- common_parent = os .path .commonpath ([file_node ["path" ], get_node_path (session )])
560
+ common_parent = os .path .commonpath (
561
+ [file_node ["path" ], get_node_path (session )]
562
+ )
537
563
common_parent_path = pathlib .Path (common_parent )
538
564
print ("[vscode-pytest]: Session node now set to: " , common_parent )
539
565
session_node ["path" ] = common_parent_path # pathlib.Path
@@ -583,9 +609,13 @@ def build_nested_folders(
583
609
while iterator_path != session_node_path :
584
610
curr_folder_name = iterator_path .name
585
611
try :
586
- curr_folder_node : TestNode = created_files_folders_dict [os .fspath (iterator_path )]
612
+ curr_folder_node : TestNode = created_files_folders_dict [
613
+ os .fspath (iterator_path )
614
+ ]
587
615
except KeyError :
588
- curr_folder_node : TestNode = create_folder_node (curr_folder_name , iterator_path )
616
+ curr_folder_node : TestNode = create_folder_node (
617
+ curr_folder_name , iterator_path
618
+ )
589
619
created_files_folders_dict [os .fspath (iterator_path )] = curr_folder_node
590
620
if prev_folder_node not in curr_folder_node ["children" ]:
591
621
curr_folder_node ["children" ].append (prev_folder_node )
@@ -884,7 +914,15 @@ def send_post_request(
884
914
)
885
915
886
916
887
- @pytest .hookimpl (hookwrapper = True )
888
- def pytest_xdist_auto_num_workers (config : pytest .Config ) -> Generator [None , Result [int ], int ]:
889
- """determine how many workers to use based on how many tests were selected in the test explorer"""
890
- return min ((yield ).get_result (), len (config .option .file_or_dir ))
917
+ def pytest_configure (config : pytest .Config ):
918
+ if config .pluginmanager .hasplugin ("xdist" ):
919
+
920
+ class XdistHook :
921
+ @pytest .hookimpl (hookwrapper = True )
922
+ def pytest_xdist_auto_num_workers (
923
+ self , config : pytest .Config
924
+ ) -> Generator [None , Result [int ], int ]:
925
+ """determine how many workers to use based on how many tests were selected in the test explorer"""
926
+ return min ((yield ).get_result (), len (config .option .file_or_dir ))
927
+
928
+ config .pluginmanager .register (XdistHook ())
0 commit comments