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

时间:2015-03-27 19:49:51

标签: python pytest python-green

目前我正在使用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.

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

1 个答案:

答案 0 :(得分:4)

是的! Green支持unittest的内置unittest.skipIf(condition, reason)功能,以及skip()skipUnless()SkipTestrest of the skip functions and exceptions

@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或更高版本。