Skipping tests with green test runner in Python

448 views Asked by At

At the moment I am using py.test to run the test and define skipped test as the following:

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

Does green provide corresponding facilities if I want to migrate my tests to green?

1

There are 1 answers

0
Nathan Stocks On BEST ANSWER

Yes! Green supports unittest's built-in unittest.skipIf(condition, reason) function, as well as the rest of the skip functions and exceptions like skip(), skipUnless(), and 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."
        ...

Note that this requires Python 2.7 or later.