在 Python 中使用绿色测试运行程序跳过测试
Skipping tests with green test runner in 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,green是否提供相应的便利?
是的! Green支持unittest
内置的unittest.skipIf(condition, reason)
函数,以及rest of the skip functions and exceptions如skip()
、skipUnless()
、SkipTest
等rest 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 或更高版本。
目前我正在使用 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,green是否提供相应的便利?
是的! Green支持unittest
内置的unittest.skipIf(condition, reason)
函数,以及rest of the skip functions and exceptions如skip()
、skipUnless()
、SkipTest
等rest 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 或更高版本。