diff --git a/tests/conftest.py b/tests/conftest.py index c834e62a0..15607b6a1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -372,7 +372,8 @@ def pytest_runtest_makereport(item, call): @pytest.hookimpl(hookwrapper=True) def pytest_terminal_summary(terminalreporter): - """Group benchmark results on CI.""" + """Add custom pytest summary sections.""" + # Group benchmark results on CI. if testutils.ON_CI: terminalreporter.write_line( testutils.gha_group_begin('Benchmark results')) @@ -380,3 +381,23 @@ def pytest_terminal_summary(terminalreporter): terminalreporter.write_line(testutils.gha_group_end()) else: yield + + # List any screenshots of failed end2end tests that were generated during + # the run. Screenshots are captured from QuteProc.after_test() + properties = lambda report: dict(report.user_properties) + reports = [ + report + for report in terminalreporter.getreports("") + if "screenshot" in properties(report) + ] + screenshots = [ + pathlib.Path(properties(report)["screenshot"]) + for report in reports + ] + + if screenshots: + terminalreporter.ensure_newline() + screenshot_dir = screenshots[0].parent + terminalreporter.section(f"End2end screenshots available in: {screenshot_dir}", sep="-", blue=True, bold=True) + for screenshot in screenshots: + terminalreporter.line(screenshot.parts[-1]) diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index 5d5af7c53..8cac6c4f6 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -932,7 +932,7 @@ def screenshot_dir(request, tmp_path_factory): @pytest.fixture -def take_x11_screenshot(request, screenshot_dir, xvfb): +def take_x11_screenshot(request, screenshot_dir, record_property, xvfb): """Take a screenshot of the current pytest-xvfb display. Screenshots are saved to the location of the `screenshot_dir` fixture. @@ -952,13 +952,10 @@ def take_x11_screenshot(request, screenshot_dir, xvfb): for char in bad_chars: fname = fname.replace(char, "_") - # TODO: - # 1. Log a "screenshot saved to ..." message so that people know where - # to go look for them when running locally? Using pytest-print? Or - # add an FYI to the report summary? fpath = screenshot_dir / fname img.save(fpath) + record_property("screenshot", str(fpath)) return doit