From dc4e56cfae7d405676d0bf3d1454a1c11eb754f1 Mon Sep 17 00:00:00 2001 From: Rafal Semik Date: Thu, 9 Feb 2023 13:26:54 +0100 Subject: [PATCH] Add UT for TestReport timestamps --- testing/test_reports.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/testing/test_reports.py b/testing/test_reports.py index 31b6cf1af..e101b51da 100644 --- a/testing/test_reports.py +++ b/testing/test_reports.py @@ -6,6 +6,7 @@ from _pytest._code.code import ExceptionChainRepr from _pytest._code.code import ExceptionRepr from _pytest.config import Config from _pytest.pytester import Pytester +from _pytest.python_api import approx from _pytest.reports import CollectReport from _pytest.reports import TestReport @@ -415,6 +416,26 @@ class TestReportSerialization: result.stdout.fnmatch_lines(["E *Error: No module named 'unknown'"]) result.stdout.no_fnmatch_line("ERROR - *ConftestImportFailure*") + def test_report_timestamps_match_duration(self, pytester: Pytester, mock_timing): + reprec = pytester.inline_runsource( + """ + import pytest + from _pytest import timing + @pytest.fixture + def fixture_(): + timing.sleep(5) + yield + timing.sleep(5) + def test_1(fixture_): timing.sleep(10) + """ + ) + reports = reprec.getreports("pytest_runtest_logreport") + assert len(reports) == 3 + for report in reports: + data = report._to_json() + loaded_report = TestReport._from_json(data) + assert loaded_report.stop - loaded_report.start == approx(report.duration) + class TestHooks: """Test that the hooks are working correctly for plugins"""