Category python-pytest

Pytest parameterized tests

Pytest Parameterized Tests Parameterizing tests allows you to run them for multiple sets of inputs. We can do this by using the following markup – @pytest.mark.parametrize Copy the following code into a file called test_multiplication.py – import pytest @pytest.mark.parametrize("num, output",[(1,11),(2,22),(3,35),(4,44)])…

Pytest Xfail/Skip testing

Pytest Xfail/Skip Testing In this chapter, we will learn about Skip and Xfail testing in pytest. Now, consider the following scenario – For some reason, a test is not meaningful for a while. A new feature is being implemented, and…

Pytest fixture

Pytest fixture A fixture is a function that will run before each test function it is applied to. Fixtures are used to provide data to the test, such as a database connection, the test’s URL, and some input data. Therefore,…

Pytest Conftest.py

Pytest Conftest.py This file allows us to define fixture functions that can be used in multiple test files. Create a new file, conftest.py, and add the following code to it – import pytest @pytest.fixture def input_value(): input = 39 return…

Pytest groups tests

Grouping Tests with Pytest In this chapter, we’ll learn how to group tests using tags. Pytest allows us to use tags on test functions. Tags are used to set various features/attributes for test functions. Pytest provides many built-in tags, such…