简体   繁体   English

使用 pdb 调试 tox python 测试?

[英]Debugging tox python tests with pdb?

I've read much of the documentation around Openstack(python cloud framework) tests, tox, and testools.我已经阅读了很多关于 Openstack(python 云框架)测试、tox 和 testtools 的文档。 All I've found indicates debugging can be done, but only by running the entire test suite.我所发现的一切都表明可以进行调试,但只能通过运行整个测试套件来完成。

I'd like the ability to run a single test module with pdb.set_trace() breakpoints inserted, then step through the test.我希望能够运行插入了 pdb.set_trace() 断点的单个测试模块,然后逐步完成测试。 I've tried this but it causes test failures on a test that would otherewise succeed.我已经尝试过了,但它会导致测试失败,否则会成功。 The command I use to run the test is similar to this: tox -e py27我用来运行测试的命令类似于:tox -e py27

Is there some way to debug single tests that I haven't found?有没有办法调试我没有找到的单个测试? If not, how is everyone doing test development without the ability to debug?如果没有,没有调试能力的每个人都如何进行测试开发?

You can refer to Basic example section in https://docs.python.org/3/library/unittest.html您可以参考https://docs.python.org/3/library/unittest.html中的基本示例部分
It allows you to test singular functionalities.它允许您测试单一功能。

Example below ensures 'foo'.upper() equals 'FOO' in the unittest framework.下面的示例确保 'foo'.upper() 在unittest框架中等于 'FOO'。

import unittest

class TestStringMethods(unittest.TestCase):

    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')

if __name__ == '__main__':
    unittest.main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM