如何在PyCharm中使用py.test运行unittest.TestCase子类?

时间:2013-11-01 11:37:59

标签: python pycharm

我可以毫无问题地运行普通test_*函数的文件,但是当我尝试运行包含在unittest.TestCase子类中的测试的文件时,我得到以下结果

W:\dev\Scripts\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 3.0.1\helpers\pycharm\pytestrunner.py" -p pytest_teamcity W:/dev/datakortet/xfr/setup/tests
Testing started at 3:31 PM ...
============================= test session starts ==============================
platform win32 -- Python 2.7.3 -- pytest-2.3.5
plugins: cov, xdist
collected 0 items / 1 skipped

========================== 1 skipped in 0.57 seconds ===========================

Process finished with exit code 0
Empty test suite.

当我从命令行运行相同的测试时:

(dev) w:\dev\datakortet\xfr\setup\tests>py.test test_setup_views.py
========================================================================================= test session starts ====
platform win32 -- Python 2.7.3 -- pytest-2.3.5
plugins: cov, xdist
collected 6 items

test_setup_views.py ......

====================================================================================== 6 passed in 4.15 seconds ==

(dev) w:\dev\datakortet\xfr\setup\tests>

我是否需要在测试中添加任何内容(我没有测试套件或测试运行器,因为py.test不需要这个...)

1 个答案:

答案 0 :(得分:2)

转到各自的文件,其中包含unittest个测试。然后你需要做的是转到设置内的Python Integrated Tools。然后将默认测试运行器设置为Unittest

enter image description here

之后,你可以进入你的unittest文件,你可以运行它,它将执行测试。

或者,您可以右键单击测试所在文件的目录,然后右键单击,您应该可以看到"Run Unittests in test.py"或其他内容。这将运行所有测试

相关问题