微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Python中的绿色测试运行器跳过测试

目前,我正在使用py.test来运行测试并定义跳过的测试,如下所示:

@pytest.mark.skipif(True, reason="blockchain.info support currently disabled")
class BlockChainBTCTestCase(CoinTestCase, unittest.TestCase):   
    ...

@pytest.mark.skipif(is_slow_test_hostile(), reason="Running send + receive loop may take > 20 minutes")
def test_send_receive_external(self):
    """ Test sending and receiving external transaction within the backend wallet.

如果我想将测试迁移到绿色,绿色是否提供相应的设施?

解决方法:

是! Green支持unittest的内置unittest.skipIf(condition,reason)函数以及rest of the skip functions and exceptions(如skip(),skipUnless()和SkipTest).

@unittest.skipIf(True, reason="Just skip all the tests in the test case.")
class MyTestCase(unittest.TestCase):   
    ...

class MyOtherTestCase(unittest.TestCase):
    @unittest.skipIf(stuff_is_slow(), reason="Stuff is slow right Now.")
    def test_fast_stuff(self):
        "This is a great test if stuff is fast at the moment."
        ...

请注意,这需要Python 2.7或更高版本.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐