【发布时间】:2014-04-08 22:35:11
【问题描述】:
我刚刚“移植”了一个我正在写入 PyCharm 的 Python 包,并且在从 IDE 为整个包运行单元测试时遇到了一些麻烦。
在包的__init__.py 中,我有load_tests 函数,它遍历包中的所有模块并加载相关测试。它运行出色:
$python -m unittest my_package
但是,当我尝试从 PyCharm 运行它时(通过在“项目”窗口中选择顶级目录并按 Ctrl+Shift+F10)我在“运行”窗口中得到 No tests were found,并且 p>
...\python.exe ...\pycharm\utrunner.py .../my_package/ true
Testing started at ...
Process finished with exit code 0
Empty test suite.
在控制台窗口中。
我快速浏览了 PyCharm 的 utrunner.py,它似乎正在寻找具有特定模式的模块(以 test 开头)。我想保留目前的香草方法。如何将 PyCharm 配置为使用 __init__.py 中的 load_tests,同时尽可能少地修改代码?
顺便说一下,单个模块的测试套件在 PyCharm 中运行得很好。
使用 PyCharm 3.1 社区版、Python 2.7。
提前谢谢你。
【问题讨论】: