1
1
import itertools as it
2
+ import os
2
3
import sys
3
4
import time
4
5
from concurrent .futures import ThreadPoolExecutor
16
17
_test_count = 0 # manual reference counting since threading borks with destructors
17
18
18
19
19
- def configure (* _ , extensions : List [Extension ] = [], headless = True , selenium_dir = "drivers" , threads = 1 ):
20
+ def configure (* _ , extensions : List [Extension ] = [], headless = True , selenium_dir = "drivers" ):
20
21
global _browser_pool
21
22
22
23
if _browser_pool is not None :
@@ -26,7 +27,7 @@ def configure(*_, extensions: List[Extension] = [], headless=True, selenium_dir=
26
27
for browser in [chrome , firefox ]:
27
28
browser .setup_driver (conf .selenium_dir )
28
29
29
- _browser_pool = BrowserPool (conf , threads )
30
+ _browser_pool = BrowserPool (conf , __get_threads () )
30
31
31
32
32
33
def run_on (* browsers ):
@@ -47,7 +48,7 @@ def wrapper(test):
47
48
to_run = [* map (partial (__wrap_test , test = test ), browsers )]
48
49
49
50
def inner ():
50
- if 1 or "--tests-per-worker" in sys .argv :
51
+ if "--tests-per-worker" in sys .argv :
51
52
with ThreadPoolExecutor (max_workers = len (to_run )) as pool :
52
53
pool .map (lambda test_ : test_ (), to_run )
53
54
else :
@@ -90,3 +91,16 @@ def inner():
90
91
inner .__doc__ = test .__doc__
91
92
92
93
return inner
94
+
95
+
96
+ def __get_threads (args = sys .argv ):
97
+ if "--tests-per-worker" not in args :
98
+ return 1
99
+ tests_per_worker_idx = args .index ("--tests-per-worker" )
100
+ next_arg = "" .join (args [tests_per_worker_idx + 1 : tests_per_worker_idx + 2 ])
101
+ if next_arg == "auto" :
102
+ return os .cpu_count () // 2 + 1
103
+ try :
104
+ return int ("0" + next_arg ) // 2 + 1
105
+ except ValueError :
106
+ return 1
0 commit comments