Fix --fail-under with SystemExit raising from pytest or script#73
Open
ownik wants to merge 2 commits intoplasma-umass:mainfrom
Open
Fix --fail-under with SystemExit raising from pytest or script#73ownik wants to merge 2 commits intoplasma-umass:mainfrom
ownik wants to merge 2 commits intoplasma-umass:mainfrom
Conversation
e6b45f6 to
1fad013
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the --fail-under flag when running pytest as a module with slipcover. Previously, pytest would raise a SystemExit exception through runpy.run_module, preventing the --fail-under code from executing. The fix catches the SystemExit exception and preserves the exit code to return it after the coverage check completes.
Changes:
- Added exception handling to catch
SystemExitfromrunpy.run_module()and preserve the exit code - Modified return logic to return the captured exit code instead of always returning 0
- Added test cases to verify
--fail-underworks correctly when running pytest as a module
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/slipcover/main.py | Added try-except block to catch SystemExit from pytest and preserve its exit code for proper propagation |
| tests/test_coverage.py | Added test cases verifying --fail-under works with pytest module execution |
Comments suppressed due to low confidence (1)
src/slipcover/main.py:302
- The script execution path (lines 277-302) doesn't catch
SystemExitexceptions like the module execution path does (lines 308-311). This inconsistency means scripts that callsys.exit()would still terminate slipcover prematurely, preventing--fail-underchecks. Consider wrapping the exec() call with similar exception handling for consistency.
exec(code, script_globals)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pytest raises SystemExit when it running as runpy.run_module and code block with --fail-under never ran before.
Script can raises SystemExit when it running through exec function and code block with --fail-under never ran before.
1fad013 to
d20fa51
Compare
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.
pytest or python script could raise SystemExit and code block with --fail-under never ran before.