A Python testing framework called
pytest makes it easy and simple to create small, understandable tests and has the capacity to handle complex functional testing for programmes and modules.
One of the important functionalities provided by pytest is markers. Markers are used to set metadata, such as, different characteristics and properties to test functions. The markers are attached to a test function in the form of function decorators. There are some inbuilt markers like
skip and so on.
skip is one such marker provided by pytest that is used to skip test functions from executing.
The syntax to use the
skip mark is as follows:
@pytest.mark.skip(reason="reason for skipping the test case") def test_case(): ....
We can specify why we skip the test case using the
reason argument of the
Le’s look at the code below:
import pytest @pytest.mark.skip(reason="Dependent feature not yet ready") def test_new_feature(): print("New feature") def test_login(): print("Test Login")
test_new_feature(). This function is annotated with the
skipmarker decorator with the reason as
Dependent feature not yet ready.
In the output, we can observe that
test_new_feature() test case is skipped while
test_login() is executed.
View all Courses