Skip to content

Commit 8d04ad9

Browse files
msabramoicemac
andauthored
Fix NotImplementedError crash when using xdist schedulers without mark_test_pending (#309)
* Fix NotImplementedError crash when using xdist schedulers without mark_test_pending Handle gracefully when pytest-xdist schedulers (like LoadScopeScheduling) don't implement mark_test_pending by catching NotImplementedError and failing the test with a clear message instead of crashing the test run. When a test crashes and cannot be rescheduled: - Set report outcome to "failed" with informative error message - Explain which scheduler lacks rescheduling support - Show remaining rerun count that couldn't be used - Continue test execution instead of internal crash Fixes #247 --------- Co-authored-by: Michael Howitz <icemac@gmx.net>
1 parent cb8ede7 commit 8d04ad9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/pytest_rerunfailures.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,24 @@ def pytest_handlecrashitem(self, crashitem, report, sched):
361361
db = sched.config.failures_db
362362
reruns = db.get_test_reruns(crashitem)
363363
if db.get_test_failures(crashitem) < reruns:
364-
sched.mark_test_pending(crashitem)
365-
report.outcome = "rerun"
364+
try:
365+
sched.mark_test_pending(crashitem)
366+
report.outcome = "rerun"
367+
except NotImplementedError:
368+
# Some schedulers (like LoadScopeScheduling) don't implement
369+
# mark_test_pending
370+
# In this case, we can't reschedule the crashed test for rerun
371+
# Mark it as failed with a clear message about why it couldn't be rerun
372+
report.outcome = "failed"
373+
if not hasattr(report, "longrepr") or report.longrepr is None:
374+
error_msg = (
375+
"Test crashed and could not be rescheduled for rerun."
376+
f" The scheduler '{sched.__class__.__name__}' does not support"
377+
" rescheduling crashed tests"
378+
" (mark_test_pending not implemented)."
379+
f" Remaining reruns: {reruns - db.get_test_failures(crashitem)}"
380+
)
381+
report.longrepr = error_msg
366382

367383
db.add_test_failure(crashitem)
368384

0 commit comments

Comments
 (0)