Skip to content

Commit d4795d1

Browse files
committed
Better detection of multithreading to alter test behavior
1 parent fe840c8 commit d4795d1

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _add_chrome_proxy_extension(
9595
""" Implementation of https://stackoverflow.com/a/35293284 for
9696
https://stackoverflow.com/questions/12848327/
9797
(Run Selenium on a proxy server that requires authentication.) """
98-
if not "".join(sys.argv) == "-c":
98+
if not ("-n" in sys.argv or "".join(sys.argv) == "-c"):
9999
# Single-threaded
100100
proxy_helper.create_proxy_zip(proxy_string, proxy_user, proxy_pass)
101101
else:
@@ -529,7 +529,8 @@ def get_local_driver(
529529
logging.debug("\nWarning: Could not make geckodriver"
530530
" executable: %s" % e)
531531
elif not is_geckodriver_on_path():
532-
if not "".join(sys.argv) == "-c": # Skip if multithreaded
532+
if not ("-n" in sys.argv or "".join(sys.argv) == "-c"):
533+
# (Not multithreaded)
533534
from seleniumbase.console_scripts import sb_install
534535
sys_args = sys.argv # Save a copy of current sys args
535536
print("\nWarning: geckodriver not found!"
@@ -600,7 +601,8 @@ def get_local_driver(
600601
else:
601602
return webdriver.Edge()
602603
elif browser_name == constants.Browser.SAFARI:
603-
if "".join(sys.argv) == "-c": # Skip if multithreaded
604+
if ("-n" in sys.argv or "".join(sys.argv) == "-c"):
605+
# Skip if multithreaded
604606
raise Exception("Can't run Safari tests in multi-threaded mode!")
605607
return webdriver.Safari()
606608
elif browser_name == constants.Browser.OPERA:
@@ -631,7 +633,8 @@ def get_local_driver(
631633
logging.debug("\nWarning: Could not make chromedriver"
632634
" executable: %s" % e)
633635
elif not is_chromedriver_on_path():
634-
if not "".join(sys.argv) == "-c": # Skip if multithreaded
636+
if not ("-n" in sys.argv or "".join(sys.argv) == "-c"):
637+
# (Not multithreaded)
635638
from seleniumbase.console_scripts import sb_install
636639
sys_args = sys.argv # Save a copy of current sys args
637640
print("\nWarning: chromedriver not found. Installing now:")

seleniumbase/plugins/pytest_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ def pytest_configure(config):
402402
sb_config.pytest_html_report = config.getoption('htmlpath') # --html=FILE
403403

404404
if sb_config.reuse_session:
405-
if "".join(sys.argv) == "-c": # Can't "reuse_session" if multithreaded
405+
if "-n" in sys.argv or "".join(sys.argv) == "-c":
406+
# Can't "reuse_session" if multithreaded
406407
sb_config.reuse_session = False
407408

408409
if "linux" in sys.platform and (

0 commit comments

Comments
 (0)