【问题标题】:How should I indicate that a test hasn't been written yet in Python?我应该如何表明尚未用 Python 编写测试?
【发布时间】:2012-08-20 02:08:39
【问题描述】:

我正在使用 Python 和 unittest 模块进行 TDD。在 NUnit 中你可以Assert.Inconclusive("This test hasn't been written yet")。

到目前为止,我还没有在 Python 中找到任何类似的东西来表明“这些测试只是占位符,我需要回来并将代码实际放入其中。”

这有 Pythonic 模式吗?

【问题讨论】:

  • 不幸的是,这不是一个单元测试人员,但是pass 怎么样?

标签: python unit-testing tdd


【解决方案1】:

我经常使用 self.fail 作为待办事项列表

def test_some_edge_case(self):
    self.fail('Need to check for wibbles')

当我在做 tdd 时对我很有效。

【讨论】:

    【解决方案2】:

    使用new and updated unittest module,您可以跳过测试:

    @skip("skip this test")
    def testSomething(self):
        pass # TODO
    
    def testBar(self):
        self.skipTest('We need a test here, really')
    
    def testFoo(self):
        raise SkipTest('TODO: Write a test here too')
    

    当测试运行器运行这些时,它们被单独计算(“skipped: (n)”)。

    【讨论】:

      【解决方案3】:

      我不会让他们通过或显示 OK,因为你不会轻易找到他们。

      也许只是让他们失败和原因(尚未写),这似乎合乎逻辑,因为您有一个尚未完成的测试。

      【讨论】:

        猜你喜欢
        • 2011-11-10
        • 1970-01-01
        • 2011-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多