How to Test a Single File Under Pytest

Better Stack Team
Updated on May 15, 2024

To run a single test file with pytest, use the command pytest followed by the file path:

 
pytest tests/test_file.py

To execute a specific test within that file, append :: and the test name to the file path:

 
pytest tests/test_file.py::test_name
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.