使用Python pudb调试器和pytest

yag*_*ger 16 python pytest pudb

之前我选择的测试库是单元测试.它正在使用我最喜欢的调试器--Pudb.不是Pdb !!!

要将Pudbunittest 一起使用,我会import pudb;pudb.set_trace()在代码行之间粘贴.然后我执行了python -m unittest my_file_test,其中my_file_testmy_file_test.py文件的模块表示.

简单地使用nosetests my_file_test.py将无法工作 - AttributeError: StringIO instance has no attribute 'fileno'将被抛出.

随着py.test既不作品:
py.test my_file_test.py
也不
python -m pytest my_file_test.py

两个扔 ValueError: redirected Stdin is pseudofile, has no fileno()

有关如何使用任何想法Pudbpy.test

yag*_*ger 16

只需添加-s标志就不会替换stdin和stdout,并且可以访问调试,即pytest -s my_file_test.py可以解决问题.

在ambi提供的文档中,也可以说以前使用显式的-s也是常规pdb所必需的,现在-s标志与--pdb标志一起隐式使用.

但是py.test不会隐式支持pUdb,因此需要设置-s.


amc*_*gor 9

更新的答案是,现在有一个适配器库可用于公开--pudb类似于一个的跟踪选项--pdb.当然,更通用的-s选项仍然是来自任何调试器的手动放置断点的有效解决方案.

要使用,请pip install pytest-pudb执行Pytest via py.test --pudb.此外,import pudb; pudb.set_trace()功能,而不需要支持-s--capture=no是否已安装此适配器.