0

我正在使用 eclipse 并且试图在我的单元测试类中只运行 1 个测试函数,而不是每次都运行所有函数。我该怎么做?这是我的测试类的样子:

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 新手。

4

1 回答 1

0

要从命令行运行单个单元测试,请使用:

可以从命令行使用 unittest 模块从模块、类甚至单个测试方法运行测试:

python -m unittest test_module1 test_module2
python -m unittest test_module.TestClass
python -m unittest test_module.TestClass.test_method

阅读更多@单元测试

在你的情况下,是这样的:

$ python -m unittest test_module.XTest.test_firstTest
于 2013-10-04T19:22:09.623 回答