Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore some unittest test in Pycharm 2017.1?

There is a button "Show Ignored" in Pycharm test run window. I wonder, how to mark some test as ignored?

Pycharm screenshot

like image 782
Alexander C Avatar asked Jun 23 '17 14:06

Alexander C


1 Answers

With just Python unittest, you can decorate a test to be skipped with @skip. From unittest — Unit testing framework — Python 2 or unittest — Unit testing framework — Python 3:

class MyTestCase(unittest.TestCase):

    @unittest.skip("demonstrating skipping")
    def test_nothing(self):
        self.fail("shouldn't happen")

    @unittest.skipIf(mylib.__version__ < (1, 3),
                     "not supported in this library version")
    def test_format(self):
        # Tests that work for only a certain version of the library.
        pass

    @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
    def test_windows_support(self):
        # windows specific testing code
        pass

I assume PyCharm is showing you the skipped tests.

like image 162
Joe P Avatar answered Sep 24 '22 19:09

Joe P