Search⌘ K
AI Features

Skipping Tests With pytest

Understand how to use pytest to skip tests conditionally, including using skip functions and decorators. Learn to manage test execution based on environment factors like interpreter version or operating system, improving your testing efficiency in Python OOP projects.

We'll cover the following...

Overview

It is sometimes necessary to skip tests in pytest, for a similar variety of reasons: the code being tested hasn’t been written yet, the test only runs on certain interpreters or operating systems, or the test is time-consuming and should only be run under certain circumstances.

The skip() function

One way to skip tests is by using the pytest.skip() function. It accepts a single argument: a string describing why it has been skipped. This function can be called anywhere. If we call it inside a test function, the test will be skipped. If we call it at the module level, all the tests in ...