Search code examples
pythonunit-testingnosegitlab-ci

Suppress a specific type of exceptions in nose


I set up a CI pipeline (Gitlab CI if that matters) for my latest Python project and added several test cases for things I still want to implement. In each test case I raise a NotImplementedError since, well, it has not been implemented yet.

import unittest

class GenericTest(unittest.TestCase):

    def test_stuff(self):
        """I'll fill this in when I come around to it."""
        raise NotImplementedError

Generally, I want these tests to fail, since do not yet work properly. However, when I push to my repository and the tests are run on the CI system, I would like to skip these tests. I already know they will 'fail' and they mask actual failing tests.

Is there a way to suppress these exceptions, or a specific type of exception (like IKnowThisWillFailError), so that the affected tests are not counted as 'failed'?


Solution

  • what about

    import unittest
    
    class GenercTest(unittest.TestCase):
    
        def test_stuff(self):
            """I'll fill this in when I come around to it."""
            raise unittest.SkipTest("IKnowThisWillFail")
    

    your CI system probably can differentiate between skipped and failed tests