7
7
from functools import partial , wraps
8
8
from typing import Iterable , List , Optional
9
9
10
- from autoparaselenium .browsers import chrome , firefox
11
10
from autoparaselenium .browser_pool import BrowserPool
11
+ from autoparaselenium .browsers import chrome , firefox
12
12
from autoparaselenium .models import Conf , Extension
13
13
14
-
15
14
_browser_pool : Optional [BrowserPool ] = None
16
15
all_ = [chrome , firefox ]
17
16
18
- _test_count = 0 # manual reference counting since threading borks with destructors
17
+ _test_count = 0 # manual reference counting since threading borks with destructors
19
18
20
19
21
- def configure (* _ , extensions : List [Extension ] = [], headless = True , selenium_dir = "drivers" ):
20
+ def configure (
21
+ * _ , extensions : List [Extension ] = [], headless = True , selenium_dir = "drivers"
22
+ ):
22
23
global _browser_pool
23
24
24
25
if _browser_pool is not None :
@@ -37,7 +38,6 @@ def run_on(*browsers):
37
38
if not browsers :
38
39
raise TypeError ("Please specify a browser or browser list to run on" )
39
40
40
-
41
41
if isinstance (browsers [0 ], Iterable ):
42
42
browsers = [* it .chain (* browsers )]
43
43
@@ -70,25 +70,28 @@ def __wrap_test(browser, test):
70
70
_test_count += 1
71
71
72
72
if _browser_pool is None :
73
- raise RuntimeError ("Please call autoparaselenium.configure() before creating tests" )
73
+ raise RuntimeError (
74
+ "Please call autoparaselenium.configure() before creating tests"
75
+ )
74
76
75
77
def inner ():
76
78
global _test_count
77
79
78
80
try :
79
81
_test_count -= 1
80
82
driver = _browser_pool .acquire (browser )
81
- driver .get ("data:," ) # initialize driver website
83
+ driver .get ("data:," ) # initialize driver website
82
84
test (driver )
83
85
finally :
84
86
with suppress (Exception ):
85
87
_browser_pool .release (driver )
86
88
87
89
if _test_count == 0 :
88
- time .sleep (0.10 ) # idk but seems like it needs a bit of time before you can close the pool
90
+ time .sleep (
91
+ 0.10
92
+ ) # idk but seems like it needs a bit of time before you can close the pool
89
93
_browser_pool .clean_up ()
90
94
91
-
92
95
inner .__name__ = f"{ test .__name__ } __{ 'chrome' if browser is chrome else 'firefox' } "
93
96
inner .__doc__ = test .__doc__
94
97
@@ -99,7 +102,7 @@ def __get_threads(args=sys.argv):
99
102
if "--tests-per-worker" not in args :
100
103
return 1
101
104
tests_per_worker_idx = args .index ("--tests-per-worker" )
102
- next_arg = "" .join (args [tests_per_worker_idx + 1 : tests_per_worker_idx + 2 ])
105
+ next_arg = "" .join (args [tests_per_worker_idx + 1 : tests_per_worker_idx + 2 ])
103
106
if next_arg == "auto" :
104
107
return os .cpu_count () // 2 + 1
105
108
try :
0 commit comments