Opened 10 months ago
Closed 10 months ago
#36057 closed New feature (fixed)
Make `test --pdb` pass exception to `pdb.post_mortem()` on Python 3.13
| Reported by: | Adam Johnson | Owned by: | Adam Johnson |
|---|---|---|---|
| Component: | Testing framework | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Python 3.13 added support for navigating between chained exceptions in pdb with the new 'exceptions' command.
Currently, using test --pdb does not allow this navigation, failing with this message:
(Pdb) exceptions Did not find chained exceptions. To move between exceptions, pdb/post_mortem must be given an exception object rather than a traceback.
PDBDebugResult currently passes pdb.post_mortem() the traceback object. But it turns out that the pdb changes in 3.13 also allow passing an exception here, which is currently undocumented but I submitted a PR.
If we switch to passing the exception, it enables switching between chained exceptions:
> /.../django/core/management/commands/dumpdata.py(285)handle()
-> raise CommandError("Unable to serialize database: %s" % e)
(Pdb) exceptions
0 TypeError("string argument expected, got 'bytes'")
> 1 CommandError("Unable to serialize database: string argument expected, got 'by...
(Pdb) exceptions 0
> /.../django/core/management/base.py(181)write()
-> self._out.write(style_func(msg))
(Pdb)
(I actually made this change to debug a chained exception failure whilst working on #36056.)
Change History (6)
comment:1 by , 10 months ago
| Has patch: | set |
|---|---|
| Owner: | set to |
| Status: | new → assigned |
comment:2 by , 10 months ago
comment:3 by , 10 months ago
| Triage Stage: | Unreviewed → Accepted |
|---|
Thank you Adam! After some investigation following your links, I think this makes sense. I haven't checked myself yet, but do you think there is a sensible test to add to ensure we don't regress in this code? Also, a nitpick, the commit message should "Refs #34900" (same with the other Python 3.13 related ticket).
comment:4 by , 10 months ago
I haven't checked myself yet, but do you think there is a sensible test to add to ensure we don't regress in this code?
We don’t seem to have any test coverage of the --pdb option right now, so it’s not super easy to add. Even if we did, I don’t think we can easily do it without mocking pdb, which wouldn't cover the change here.
Also, a nitpick, the commit message should "Refs #34900" (same with the other Python 3.13 related ticket).
Should it? This is to take advantage of a new feature, not to fix something for the new version. Similarly, my other ticket is a bug that existed before 3.13, just got better exposed by it.
comment:5 by , 10 months ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
pytest is already taking advantage of this “secret feature“: https://github.com/pytest-dev/pytest/issues/12707