Repository navigation
fix: don't enter the debugger for a syntax error - #15239
ShahabAhmed01 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Local validation for this change, run on
The full The debugger is still entered for other collection errors — |
|
Follow-up on the second commit ( The first version of the helper had a A local coverage run with the repository's own configuration ( The subprocess coverage matters here: the syntax-error path only runs in the child process that
|
When a test module cannot be imported because of a syntax error, pytest re-raises the error as a CollectError. With --pdb the debugger was then entered at the place where the error is re-raised, which is not helpful: the actual syntax error is only visible in the traceback. Detect the syntax error -- the CollectError keeps it as its cause -- and skip the debugger in that case. The error is reported as before. Closes pytest-dev#3649 Co-authored-by: MiniMax M3.1 Flash <noreply@minimax.io>
The helper is only called once an exception was raised, so the "did not raise" branch can never be taken. pytest's codecov/patch target is 100% of the changed lines, so the dead branch has to go. Co-authored-by: MiniMax M3.1 Flash <noreply@minimax.io>
28d81d9 to
866e99a
Compare
Summary
When a test module cannot be imported because of a syntax error, pytest re-raises the error as a
CollectError. With--pdbthe debugger was then entered at the place where the error is re-raised, which is not helpful: the actual syntax error is only visible in the traceback that pytest prints.The
CollectErrorkeeps the originalSyntaxErroras its cause, so the debugger is now skipped for exactly this case. The error is reported as before.Other collection errors (for example the
NameErrorof #181) still open the debugger.Closes #3649
Changelog
changelog/3649.bugfix.rstChecklist
closes #3649to the PR description and/or commits.changelogdirectory.AUTHORSin alphabetical order.Co-authored-bycommit trailers.Testing
pytest testing/— 4698 passed, 47 skipped, 13 xfailedpytest testing/test_debugging.py— 54 passed, 1 skippedruff check src/_pytest/runner.py testing/test_debugging.py— cleanruff format --check src/_pytest/runner.py testing/test_debugging.py— cleanmypy src/_pytest/runner.py— cleanThe new test
testing/test_debugging.py::TestPDB::test_pdb_not_entered_on_syntax_errorfails without the change.AI assistance
This change was prepared with AI assistance (OpenCode, using the MiniMax M3.1 Flash model) and was reviewed, tested and submitted by a human contributor. The commit carries a
Co-authored-bytrailer.I first tried to open an issue comment with the root-cause analysis, but this account is not allowed to comment on other users issues in this repository, so the analysis is in this description instead.