![](/img/trans.png)
[英]Python tox and py.test: how to run just a single test rather than the whole test suite
[英]Is there a way to run a single unit test function instead of the whole test class in Python?
我正在使用eclipse,并尝试仅在我的单元测试类中运行测试功能之一,而不是每次都运行所有功能。 我该怎么做? 这是我的测试类的样子:
import unittest
from X import func1
from X import func2
class XTest(unittest.TestCase):
def test_firstTest(self):
assertEqual(func1(), "hello")
def test_secondTest(self):
assertEqual(func2(), "bye")
if __name__ == "__main__":
unittest.main()
在eclipse中,如果我将其作为python单元测试运行,则两个测试函数都将运行。 我只想运行其中一个功能。 例如,仅test_firsttest。 抱歉,如果这很琐碎,我是Python的新手。
要从命令行运行单个单元测试,请使用:
可以从命令行使用unittest模块从模块,类甚至单个测试方法运行测试:
python -m unittest test_module1 test_module2
python -m unittest test_module.TestClass
python -m unittest test_module.TestClass.test_method
阅读更多@ unittest
您的情况是这样的:
$ python -m unittest test_module.XTest.test_firstTest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.