From 39b1776801b01ee6ebce099039af4c7685b6f621 Mon Sep 17 00:00:00 2001 From: grdddj Date: Tue, 3 Jan 2023 15:08:53 +0100 Subject: [PATCH] feat(tests): add pytest flag to not generate reports after each test [no changelog] --- core/Makefile | 10 +++++++--- tests/conftest.py | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/Makefile b/core/Makefile index 629dcc2d60..b3d3b999b5 100644 --- a/core/Makefile +++ b/core/Makefile @@ -106,13 +106,17 @@ test_emu_click: ## run click tests $(EMU_TEST) $(PYTEST) $(TESTPATH)/click_tests $(TESTOPTS) test_emu_ui: ## run ui integration tests - $(EMU_TEST) $(PYTEST) $(TESTPATH)/device_tests --ui=test --ui-check-missing $(TESTOPTS) + $(EMU_TEST) $(PYTEST) $(TESTPATH)/device_tests $(TESTOPTS) \ + --ui=test --ui-check-missing --not-generate-report-after-each-test test_emu_ui_multicore: ## run ui integration tests using multiple cores - $(PYTEST) -n auto $(TESTPATH)/device_tests $(TESTOPTS) --ui=test --ui-check-missing --control-emulators --model=core --random-order-seed=$(shell echo $$RANDOM) + $(PYTEST) -n auto $(TESTPATH)/device_tests $(TESTOPTS) \ + --ui=test --ui-check-missing --not-generate-report-after-each-test \ + --control-emulators --model=core --random-order-seed=$(shell echo $$RANDOM) test_emu_ui_record: ## record and hash screens for ui integration tests - $(EMU_TEST) $(PYTEST) $(TESTPATH)/device_tests --ui=record --ui-check-missing $(TESTOPTS) + $(EMU_TEST) $(PYTEST) $(TESTPATH)/device_tests $(TESTOPTS) \ + --ui=record --ui-check-missing --not-generate-report-after-each-test test_emu_ui_record_multicore: ## quickly record all screens make test_emu_ui_multicore || echo "All errors are recorded in fixtures.json" diff --git a/tests/conftest.py b/tests/conftest.py index 001e328837..22403452bd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -351,6 +351,13 @@ def pytest_addoption(parser: "Parser") -> None: help="Which emulator to use: 'core' or 'legacy'. " "Only valid in connection with `--control-emulators`", ) + parser.addoption( + "--not-generate-report-after-each-test", + action="store_true", + default=False, + help="Not generating HTML reports after each test case. " + "Useful for CI tests to speed them up.", + ) def pytest_configure(config: "Config") -> None: @@ -399,8 +406,11 @@ def pytest_runtest_teardown(item: pytest.Item) -> None: # Not calling `testreport.generate_reports()` not to generate # the `all_screens` report, as would take a lot of time. # That will be generated in `pytest_sessionfinish`. - if item.session.config.getoption("ui"): - testreport.index() + + # Optionally generating `index.html` report unless turned off by `pytest` flag + if not item.session.config.getoption("not_generate_report_after_each_test"): + if item.session.config.getoption("ui"): + testreport.index() @pytest.hookimpl(tryfirst=True, hookwrapper=True)