Skip to content

Commit 356040e

Browse files
committed
Avoid unnecessary work when pytest does not find tests to run
1 parent 0715837 commit 356040e

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

seleniumbase/plugins/pytest_plugin.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,11 @@ def pytest_configure(config):
14891489
if sb_config.dash_title:
14901490
constants.Dashboard.TITLE = sb_config.dash_title.replace("_", " ")
14911491

1492-
if "--co" not in sys_argv and "--collect-only" not in sys_argv:
1492+
if (
1493+
sb_config._multithreaded
1494+
and "--co" not in sys_argv
1495+
and "--collect-only" not in sys_argv
1496+
):
14931497
from seleniumbase.core import log_helper
14941498
from seleniumbase.core import download_helper
14951499
from seleniumbase.core import proxy_helper
@@ -1586,16 +1590,23 @@ def pytest_deselected(items):
15861590

15871591
def pytest_collection_finish(session):
15881592
"""This runs after item collection is finalized.
1589-
Print the dashboard path if at least one test runs.
15901593
https://docs.pytest.org/en/stable/reference.html
15911594
"""
15921595
if "--co" in sys_argv or "--collect-only" in sys_argv:
15931596
return
1597+
if len(session.items) > 0 and not sb_config._multithreaded:
1598+
from seleniumbase.core import log_helper
1599+
from seleniumbase.core import download_helper
1600+
from seleniumbase.core import proxy_helper
1601+
1602+
log_helper.log_folder_setup(sb_config.log_path, sb_config.archive_logs)
1603+
download_helper.reset_downloads_folder()
1604+
proxy_helper.remove_proxy_zip_if_present()
15941605
if sb_config.dashboard and len(session.items) > 0:
15951606
_create_dashboard_assets_()
1596-
# Output Dashboard info to the console
1607+
# Print the Dashboard path if at least one test runs.
15971608
sb_config.item_count_untested = sb_config.item_count
1598-
dash_path = os.getcwd() + "/dashboard.html"
1609+
dash_path = os.path.join(os.getcwd(), "dashboard.html")
15991610
star_len = len("Dashboard: ") + len(dash_path)
16001611
try:
16011612
terminal_size = os.get_terminal_size().columns
@@ -1694,7 +1705,9 @@ def pytest_sessionfinish(session):
16941705
def pytest_terminal_summary(terminalreporter):
16951706
if "--co" in sys_argv or "--collect-only" in sys_argv:
16961707
return
1697-
latest_logs_dir = os.getcwd() + "/latest_logs/"
1708+
if not sb_config.item_count > 0:
1709+
return
1710+
latest_logs_dir = os.path.join(os.getcwd(), "latest_logs") + os.sep
16981711
if sb_config._multithreaded:
16991712
if os.path.exists(latest_logs_dir) and os.listdir(latest_logs_dir):
17001713
sb_config._has_exception = True
@@ -1739,7 +1752,7 @@ def _perform_pytest_unconfigure_():
17391752
except Exception:
17401753
pass
17411754
sb_config.shared_driver = None
1742-
if hasattr(sb_config, "log_path"):
1755+
if hasattr(sb_config, "log_path") and sb_config.item_count > 0:
17431756
log_helper.archive_logs_if_set(
17441757
sb_config.log_path, sb_config.archive_logs
17451758
)

0 commit comments

Comments
 (0)