之前我选择的测试库是 unittest。它与我最喜欢的调试器 - PuDB 一起工作。不是 Pdb!!!
要将 PuDB 与 unittest 结合使用,我将 import pudb;pudb.set_trace()
粘贴到代码行之间。
然后我执行了 python -m unittest my_file_test
,其中 my_file_test 是 my_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()
如何将 Pudb 与 py.test 一起使用?
最佳答案
只需添加 -s 标志,pytest 将不会替换 standard input和 standard output并且可以进行调试,即 pytest -s my_file_test.py
可以解决问题。
在 ambi 提供的文档中,还说以前明确使用 -s 也是常规 pdb 所必需的,但现在是 -s 标志隐式地与 --pdb 标志一起使用。
但是,pytest 并不隐式支持 PuDB,因此需要设置 -s。
关于python - 将 Python PuDB 调试器与 pytest 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25182812/