I'm trying to debug a Python CLI I wrote that can take its arguments from stdin. A simple test case would have the output of
echo "test" | python mytool.py
be equivalent to the output of
python mytool.py test
I'd like to debug some issues with this tool, so I tried to run this:
echo "test" | pdb mytool.py
But I get this output, then pdb exits:
> /path/to/mytool.py(5)<module>()
-> '''
(Pdb) *** NameError: name 'test' is not defined
(Pdb)
The same thing occurs when I add -m python
to the shebang, and if I run pdb.set_trace()
inside the script.
What's going on here?
sys.stdin
? Also, do you just want to write a test for this or do you need to start the debugger within the script? If you need the debugger, at which point do you want it to engage the script? Sorry, the question is a bit unclear to me.