From 54320aa84b7840b7d154658b9cb906ec9b200f5e Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 5 Dec 2024 22:46:10 -0500 Subject: [PATCH 1/6] Mostly pytest updates --- examples/master_qa/pytest.ini | 2 +- examples/migration/raw_selenium/pytest.ini | 2 +- examples/pytest.ini | 2 +- examples/translations/pytest.ini | 2 +- pyproject.toml | 2 +- pytest.ini | 2 +- seleniumbase/console_scripts/sb_mkdir.py | 2 +- seleniumbase/plugins/pytest_plugin.py | 125 +++++++++++++++++++-- 8 files changed, 124 insertions(+), 15 deletions(-) diff --git a/examples/master_qa/pytest.ini b/examples/master_qa/pytest.ini index 8f2cb219ab4..0b8fa185bab 100644 --- a/examples/master_qa/pytest.ini +++ b/examples/master_qa/pytest.ini @@ -1,7 +1,7 @@ [pytest] # Display console output. Disable cacheprovider: -addopts = --capture=no -p no:cacheprovider +addopts = --capture=tee-sys -p no:cacheprovider # Skip these directories during test collection: norecursedirs = .* build dist recordings temp assets diff --git a/examples/migration/raw_selenium/pytest.ini b/examples/migration/raw_selenium/pytest.ini index 5478c5d12e5..a1f9578ce5e 100644 --- a/examples/migration/raw_selenium/pytest.ini +++ b/examples/migration/raw_selenium/pytest.ini @@ -1,7 +1,7 @@ [pytest] # Display console output. Disable cacheprovider: -addopts = --capture=no -p no:cacheprovider +addopts = --capture=tee-sys -p no:cacheprovider # Skip these directories during test collection: norecursedirs = .* build dist recordings temp assets diff --git a/examples/pytest.ini b/examples/pytest.ini index 8e6ebeda9fc..38ebd219597 100644 --- a/examples/pytest.ini +++ b/examples/pytest.ini @@ -1,7 +1,7 @@ [pytest] # Display console output. Disable cacheprovider: -addopts = --capture=no -p no:cacheprovider +addopts = --capture=tee-sys -p no:cacheprovider # Skip these directories during test collection: norecursedirs = .* build dist recordings temp assets diff --git a/examples/translations/pytest.ini b/examples/translations/pytest.ini index 8f2cb219ab4..0b8fa185bab 100644 --- a/examples/translations/pytest.ini +++ b/examples/translations/pytest.ini @@ -1,7 +1,7 @@ [pytest] # Display console output. Disable cacheprovider: -addopts = --capture=no -p no:cacheprovider +addopts = --capture=tee-sys -p no:cacheprovider # Skip these directories during test collection: norecursedirs = .* build dist recordings temp assets diff --git a/pyproject.toml b/pyproject.toml index 336999d3b49..02bc74f6768 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ packages = [ ] [tool.pytest.ini_options] -addopts = ["--capture=no", "-p no:cacheprovider"] +addopts = ["--capture=tee-sys", "-p no:cacheprovider"] norecursedirs = [".*", "build", "dist", "recordings", "temp", "assets"] filterwarnings = [ "ignore::pytest.PytestWarning", diff --git a/pytest.ini b/pytest.ini index 8e6ebeda9fc..38ebd219597 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,7 +1,7 @@ [pytest] # Display console output. Disable cacheprovider: -addopts = --capture=no -p no:cacheprovider +addopts = --capture=tee-sys -p no:cacheprovider # Skip these directories during test collection: norecursedirs = .* build dist recordings temp assets diff --git a/seleniumbase/console_scripts/sb_mkdir.py b/seleniumbase/console_scripts/sb_mkdir.py index 7db1f6b2035..585ce88cd6f 100644 --- a/seleniumbase/console_scripts/sb_mkdir.py +++ b/seleniumbase/console_scripts/sb_mkdir.py @@ -120,7 +120,7 @@ def main(): data = [] data.append("[pytest]") - data.append("addopts = --capture=no -p no:cacheprovider") + data.append("addopts = --capture=tee-sys -p no:cacheprovider") data.append("norecursedirs = .* build dist recordings temp assets") data.append("filterwarnings =") data.append(" ignore::pytest.PytestWarning") diff --git a/seleniumbase/plugins/pytest_plugin.py b/seleniumbase/plugins/pytest_plugin.py index bbab084e8a3..6f4e8dd1b04 100644 --- a/seleniumbase/plugins/pytest_plugin.py +++ b/seleniumbase/plugins/pytest_plugin.py @@ -17,6 +17,7 @@ python3_11_or_newer = True py311_patch2 = constants.PatchPy311.PATCH sys_argv = sys.argv +full_time = None pytest_plugins = ["pytester"] # Adds the "testdir" fixture @@ -2038,6 +2039,7 @@ def pytest_runtest_teardown(item): if ( "-s" in sys_argv or "--capture=no" in sys_argv + or "--capture=tee-sys" in sys_argv or ( hasattr(sb_config.pytest_config, "invocation_params") and ( @@ -2045,6 +2047,9 @@ def pytest_runtest_teardown(item): or "--capture=no" in ( sb_config.pytest_config.invocation_params.args ) + or "--capture=tee-sys" in ( + sb_config.pytest_config.invocation_params.args + ) ) ) ): @@ -2053,6 +2058,10 @@ def pytest_runtest_teardown(item): sys.stdout.write("\n=> Fail Page: %s\n" % sb_config._fail_page) +def pytest_html_duration_format(duration): + return "%.2f" % duration + + def pytest_sessionfinish(session): pass @@ -2103,9 +2112,11 @@ def pytest_terminal_summary(terminalreporter): ) -def _perform_pytest_unconfigure_(): +def _perform_pytest_unconfigure_(config): from seleniumbase.core import proxy_helper + reporter = config.pluginmanager.get_plugin("terminalreporter") + duration = time.time() - reporter._sessionstarttime if ( (hasattr(sb_config, "multi_proxy") and not sb_config.multi_proxy) or not hasattr(sb_config, "multi_proxy") @@ -2133,6 +2144,63 @@ def _perform_pytest_unconfigure_(): log_helper.clear_empty_logs() # Dashboard post-processing: Disable time-based refresh and stamp complete if not hasattr(sb_config, "dashboard") or not sb_config.dashboard: + html_report_path = None + the_html_r = None + abs_path = os.path.abspath(".") + if sb_config._html_report_name: + html_report_path = os.path.join( + abs_path, sb_config._html_report_name + ) + if ( + sb_config._using_html_report + and html_report_path + and os.path.exists(html_report_path) + ): + with open(html_report_path, "r", encoding="utf-8") as f: + the_html_r = f.read() + assets_chunk = "if (assets.length === 1) {" + remove_media = "container.classList.remove('media-container')" + rm_n_left = '
<
' + rm_n_right = '
>
' + the_html_r = the_html_r.replace( + assets_chunk, + "%s %s" % (assets_chunk, remove_media), + ) + the_html_r = the_html_r.replace(rm_n_left, "") + the_html_r = the_html_r.replace(rm_n_right, "") + the_html_r = the_html_r.replace("