Skip to content

Commit 88402b7

Browse files
committed
Add threshold for teardown durations
1 parent 8092a3f commit 88402b7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/pytest_split/plugin.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
from _pytest.config import create_terminal_writer
66

7+
# For some reason pytest reports some teardown durations to be 10M - 100M seconds long
8+
# Thus we have this threshold to not take into account the ones which are
9+
# definitely not correct
10+
STORE_DURATIONS_TEARDOWN_THRESHOLD = 60 * 10 # seconds
11+
712

813
def pytest_addoption(parser):
914
group = parser.getgroup(
@@ -80,6 +85,14 @@ def pytest_sessionfinish(session, exitstatus):
8085
for test_reports in terminal_reporter.stats.values():
8186
for test_report in test_reports:
8287
if hasattr(test_report, "duration"):
88+
stage = getattr(test_report, "when", "")
89+
duration = test_report.duration
90+
if (
91+
stage == "teardown"
92+
and duration > STORE_DURATIONS_TEARDOWN_THRESHOLD
93+
):
94+
# Ignore not legit teardown durations
95+
continue
8396
durations[test_report.nodeid] += test_report.duration
8497

8598
with open(report_path, "w") as f:

0 commit comments

Comments
 (0)