How does pytest find tests by default?
Options
- It runs every Python file in the project folder
- Files
test_*.py, functionstest_*, classesTest*(Correct option) - Only files in a folder that is named pytest
- You must register each test by hand in a file
Answer
Files named test_*.py or *_test.py, functions starting with test_, and classes starting with Test
Why
Run pytest in your project and it searches the folders for files named test_something.py, then runs every function whose name starts with test_.
If you name a function check_login(), pytest will silently ignore it.
Useful options: pytest -k login (only matching names), pytest -x (stop at first failure), pytest -v (verbose).
Remember
pytest runs test_*.py files and test_* functions.