gh-102980: Redirect pdb `interact` command, add tests and improve docs by gaogaotiantian · Pull Request #111194 · python/cpython
With the long due #102896, we can finally add tests for interact command.
However, the current interact command uses code.interact directly which makes it super difficult to test, because code.interact writes to sys.stderr directly (with sys.stderr.write)! We need to overload the write method in a derived class to write to the same channel as Pdb.message.
The interactive message is also changed to make more sense - one might wonder if this is a breaking change to users, but
- This PR will be not backported, so it's a new thing.
- The current status (plus the interactive issue in gh-102895 Add an option local_exit in code.interact to block exit() from terminating the whole process #102896 before the fix) made it almost impossible to write tests for
interactcommand, so I don't think we'll break anything.
This PR adds the class for interact commmand and some basic tests for interact; and also clarifies the namespace situation with interact - it's a bit tricky and could be confusing to the users, so some clarification is needed.
The way to exit interact command is also added to the docs.
📚 Documentation preview 📚: https://cpython-previews--111194.org.readthedocs.build/