我怎么跑unittest.TestCase子类py.测试在PyCharm?

2024-04-19 10:57:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以用普通的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.

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

^{pr2}$

我是否需要向测试添加任何内容(我没有测试套件或测试运行程序,因为py.测试不需要这个…)


Tags: 文件函数pydevtestpytestscriptsfiles
1条回答
网友
1楼 · 发布于 2024-04-19 10:57:35

使用containsunittest测试转到相应的文件。然后您需要做的是转到设置中的Python Integrated Tools。然后将默认测试运行器设置为Unittest。在

enter image description here

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

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

相关问题 更多 >