使用Python中的green test runner跳过测试

2024-04-28 12:23:15 发布

您现在位置:Python中文网/ 问答频道 /正文

目前我正在使用py.测试运行测试并将跳过的测试定义为:

@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,green是否提供相应的工具?在


Tags: pytestinfosendtruesupport定义pytest
1条回答
网友
1楼 · 发布于 2024-04-28 12:23:15

是的!Green支持unittest的内置unittest.skipIf(condition, reason)函数,以及rest of the skip functions and exceptionsskip()skipUnless(),和{}。在

@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."
        ...

请注意,这需要Python2.7或更高版本。在

相关问题 更多 >