When running nosetests I would like to drop in to an interactive console. However if I put the following anywhere in my code:
import code
code.interact(local=locals())
Nose just prints (InteractiveConsole) and does not provides the console to type in commands. Pytest treats code.interact as a failure. Is there a way I can drop into the console when running tests while also watching files for changes?
One way to get an interactive session under pytest is to set a breakpoint with
import pdb
pdb.set_trace()
Normally, pytest will supress this interactive session and will just hang when it hits the breakpoint. You can get around that by running pytest with the -s
flag, which disables command line output capturing.
In the newest version of pytest, you can just use pytest.set_trace()
without the -s
flag to get the same behavior. See the docs for info.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.