【问题标题】:Avoid setUpClass to run every time for nose cherry picked tests避免 setUpClass 每次运行鼻子樱桃采摘测试
【发布时间】: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 代替?
  • 谢谢,这正是我所需要的。如果您将其发布为答案,我会接受。

标签: python nose nosetests


【解决方案1】:

正如@jonrsharpe 所提到的,setupModule 是我所追求的:它只会在我的测试所在的整个模块中运行一次。

【讨论】:

    猜你喜欢
    • 2012-12-07
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多