Pytest Summary
Pytest Summary
In this pytest tutorial, we covered the following:
- Installing pytest.
- Identifying test files and test functions.
- Use pytest -v to execute all test files.
- Use
pytest <filename> -v
to execute a specific file. - Execute tests by substring matching: pytest -k
-v. - Execute tests based on a marker: pytest -m
-v. - Create fixtures using @pytest.fixture
- A conftest.py file allows access to fixtures from multiple files.
- Use @pytest.mark.parametrize to parameterize tests.
- Use @pytest.mark.xfail.Xfail to fail tests.
- Use @pytest.mark.skip to skip tests.
- Use
pytest --maxfail=<num>
to stop test execution after n failures. - Use
pytest -n <num>
to run tests in parallel. - Use pytest -v –junitxml=”result.xml” to generate result XML.