【发布时间】:2015-09-14 12:31:20
【问题描述】:
这是我的测试类,在mymodule.foo:
class Some TestClass(TestCase):
def setUpClass(cls):
# Do the setup for my tests
def test_Something(self)
# Test something
def test_AnotherThing(self)
# Test another thing
def test_DifferentStuff(self)
# Test another thing
我正在使用以下几行从 Python 运行测试:
tests_to_run = ['mymodule.foo:test_AnotherThing', 'mymodule.foo:test_DifferentStuff']
result = nose.run(defaultTest= tests_to_run)
(这显然有点复杂,并且有一些逻辑可以选择我想要运行的测试)
Nose 将按预期只运行选定的测试,但 setUpClass 将为 tests_to_run 中的每个测试运行一次。有什么办法可以避免吗?
我想要实现的是能够在 Python 脚本(不是从命令行)中使用 nose 时运行一些动态测试集
【问题讨论】:
-
setUp的重点是它每次都运行。也许你想要setUpModule代替? -
谢谢,这正是我所需要的。如果您将其发布为答案,我会接受。