grouping
import pytest
@pytest.mark.great
pytest -m others -v
matching substring
pytest -k <substring> -v
Fixture
-------------
import pytest
@pytest.fixture
def input_value():
input = 39
return input
def test_divisible_by_3(input_value):
assert input_value % 3 == 0
def test_divisible_by_6(input_value):
assert input_value % 6 == 0
conftest.py ---> to make a fixture available to multiple test files, we have to
define the fixture function in a file called conftest.py.
@pytest.mark.parametrize
@pytest.mark.parametrize("num, output",[(1,11),(2,22),(3,35),(4,44)])
@pytest.mark.xfail
@pytest.mark.skip
what if we want to stop the execution of test suite soon after n number of test
fails. This can be done in pytest using maxfail
pytest --maxfail = <num>
Pytest - Run Tests in Parallel
================================
pip install pytest-xdist
pytest -n 3 --------n <num> runs the tests by using multiple workers, here it is
3.
We can generate the details of the test execution in an xml file.
==================================================================
pytest test_multiplication.py -v --junitxml="result.xml"