Skip to content

Commit 242710b

Browse files
committed
Added --max-errors option to stop running the suite after specified number of subsequent errors.
1 parent 7c548d5 commit 242710b

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [0.22.0] - 2026-03-25
8+
9+
### Added
10+
11+
- Option `--max-errors` to stop running the suite after specified number of subsequent errors.
12+
713
## [0.21.0] - 2025-07-20
814

915
### Changed

docs/changelog.txt

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

55
.. currentmodule:: firebird.qa.plugin
66

7+
Version 0.22.0
8+
==============
9+
10+
* Added `--max-errors` option to stop running the suite after specified number of subsequent errors.
11+
712
Version 0.21.0
813
==============
914

src/firebird/qa/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-FileCopyrightText: 2021-present The Firebird Projects <www.firebirdsql.org>
22
#
33
# SPDX-License-Identifier: MIT
4-
__version__ = "0.21.0"
4+
__version__ = "0.22.0"

src/firebird/qa/plugin.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@
9595
SKIP_PLATFORM = 'platform'
9696
SKIP_ANY = 'any'
9797

98+
99+
# Error tracker to stop suite after X consecutive ERRORs
100+
class ErrorTracker:
101+
consecutive_errors = 0
102+
threshold_reached = False
103+
104+
tracker = ErrorTracker()
105+
98106
@pytest.fixture(scope='session', autouse=True)
99107
def log_session_context(record_testsuite_property):
100108
"""Autoused session fixture that records `version`,`architecture` and `mode`
@@ -172,6 +180,19 @@ def pytest_addoption(parser, pluginmanager):
172180
grp.addoption('--extend-xml', action='store_true', default=False, help="Extend XML JUnit report with additional information")
173181
grp.addoption('--install-terminal', action='store_true', default=False, help="Use our own terminal reporter")
174182
grp.addoption('--start-time', action='store_true', dest="start_time_info", default=False, help="Show tests start time info")
183+
parser.addoption("--max-errors", action="store", default=5, type=int,
184+
help="Number of consecutive errors before skipping. Set to 0 to disable.")
185+
186+
@pytest.hookimpl(hookwrapper=True)
187+
def pytest_runtest_call(item):
188+
"""
189+
This wraps the actual test execution. If the threshold was hit by a
190+
previous test, we skip this one immediately.
191+
"""
192+
threshold = item.config.getoption("--max-errors")
193+
if threshold > 0 and tracker.threshold_reached:
194+
pytest.skip(f"Skipping: {threshold} consecutive failures reached.")
195+
yield # Run the actual test if threshold not reached
175196

176197
def pytest_report_header(config):
177198
"""Returns plugin-specific test session header.
@@ -332,6 +353,18 @@ def pytest_runtest_makereport(item, call):
332353
333354
.. seealso:: `pytest documentation <_pytest.hookspec.pytest_runtest_makereport>` for details.
334355
"""
356+
threshold = item.config.getoption("--max-errors")
357+
if threshold > 0:
358+
if call.excinfo is not None:
359+
# Check if the test resulted in an 'ERROR' (setup/teardown) or 'FAIL'
360+
# In pytest, a DB connection crash often happens in a fixture (ERROR)
361+
tracker.consecutive_errors += 1
362+
tracker.threshold_reached = tracker.consecutive_errors >= threshold
363+
# We only care about the actual execution (call), not setup/teardown
364+
elif call.when == "call":
365+
# If a test passes, reset the streak
366+
tracker.consecutive_errors = 0
367+
#
335368
result = pytest.TestReport.from_item_and_call(item, call)
336369
for attr in dir(item):
337370
if attr.startswith('_qa_'):

0 commit comments

Comments
 (0)