如何在 pyCharm 中进行单元测试 [英] How to make unit test in pyCharm
问题描述
我想做一些单元测试,所以我设置了一个列表,其中的值都应该被断言为真,就像 这个问题.但我希望它在 PyCharm
中运行(按下 Alt
+Shift
+F10
)
I want to make some unit tests, so I set up a list with values that all should be asserted true, just like this question. But I want it to run in PyCharm
(With pressing Alt
+Shift
+F10
)
如果我只使用答案中的代码,我只会得到未找到测试
If I just use the code from the answers, I just get No tests were found
推荐答案
您需要仔细检查测试运行配置的设置:
You need to double check the settings for the tests run configuration:
默认情况下,PyCharm 将检查以 test
开头并且是 unittest.TestCase
的子类的文件,但是您可以控制 Pattern 和子类选项.
By default PyCharm will inspect files that start with test
and that are subclasses of unittest.TestCase
, however you can control the Pattern and the subclasses option.
根据您的测试文件名更改模式,它接受 Python 正则表达式.
Change Pattern according to your test file names, it accepts Python regular expression.
这篇关于如何在 pyCharm 中进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!