Python Glossary Русский

all Python 3unittestfunction

unittest.skip()

skipping tests

A decorator that unconditionally skips a test or a whole test class with the given reason.

Syntax

@unittest.skip(reason)

A bare @unittest.skip without parentheses also works, but with an empty reason, and a month later nobody remembers why the test is off, so write the reason. On a class the decorator also cancels setUpClass and tearDownClass. A skip is not a failure: the run stays green, and skipped tests show up in result.skipped and as an s in the report; review them, or tests silently rot.

Examples

import unittest
class Tests(unittest.TestCase):
    @unittest.skip('ждёт исправления API')
    def test_api(self):
        self.fail('не должно запуститься')
result = unittest.TestResult()
unittest.TestLoader().loadTestsFromTestCase(Tests).run(result)
print(result.skipped[0][1], result.wasSuccessful())  # → ждёт исправления API True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy