Skip tearDown when setUp fails, and never let tearDown crash the worker - #257
Merged
kei-nan merged 1 commit intoSep 27, 2026
Merged
Conversation
_runTest called after_func() (tearDown) unconditionally in a bare finally, even when before_func() (setUp) raised. A tearDown written against a successful setUp -- e.g. one that reads self.env -- then raises its own exception (typically AttributeError, since the attribute setUp would have assigned was never set). That second exception escaped _runTest uncaught: unlike the original setUp/test failure, it bypasses handleFailure entirely. In the parallel coordinator this kills the whole worker process instead of failing just the one test. Because RLTest schedules different methods of the same test class across different workers, a single flaky setUp (e.g. a transient env-startup connection refusal) can take down every worker in the pool near-simultaneously, and the coordinator has no way to tell a genuine "no more processors are alive" condition apart from one that will resolve once a worker finishes flushing its queued output. Track whether setUp completed, skip tearDown if it didn't, and route any exception tearDown itself raises through handleFailure like any other test failure instead of letting it propagate.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #257 +/- ##
===========================================
+ Coverage 32.46% 46.60% +14.14%
===========================================
Files 17 18 +1
Lines 2597 2755 +158
===========================================
+ Hits 843 1284 +441
+ Misses 1754 1471 -283
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
GuyAv46
approved these changes
Sep 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_runTestcalledafter_func()(tearDown) unconditionally in a barefinally, even whenbefore_func()(setUp) raised. A tearDown written against a successful setUp (e.g. one that readsself.env) then raises its own exception -- typicallyAttributeError, since the attribute setUp would have assigned was never set. That second exception escaped_runTestuncaught: unlike the original setUp/test failure, it bypasseshandleFailureentirely.exit_on_failurebranch's intent, generalized to the default path). If tearDown itself raises after a successful setUp, route it throughhandleFailurelike any other test failure instead of letting it propagate.Found while diagnosing a RediSearch nightly run where this exact pattern (
TestBM25NormMaxintest_scorers.py) hit all 4 parallel coordinator workers within ~2 seconds of each other and took the whole "Flow tests (coordinator)" CI step down for the full 120-minute timeout: https://github.com/RediSearch/RediSearch/actions/runs/36269638134/job/108481212637Test plan
tests/unit/test_teardown_after_failed_setup.pyreproducing both: (1) setUp fails -> tearDown must be skipped, not crash; (2) setUp/test succeed but tearDown itself raises -> must be reported viahandleFailure, not propagated.pytest tests/unit/) passes: 161 passed, 5 skipped.🤖 Generated with Claude Code