Test Overview
This test checks that the pytest framework can discover and run a simple test function placed in the recommended project folder structure.
It verifies that the test file is found and the test passes successfully.
This test checks that the pytest framework can discover and run a simple test function placed in the recommended project folder structure.
It verifies that the test file is found and the test passes successfully.
import pytest def test_addition(): assert 2 + 3 == 5 # Project structure: # /project_root # /tests # test_math.py (this file) # Run with: pytest tests/
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and looks for tests in the 'tests' folder | Project folder contains 'tests/test_math.py' with 'test_addition' function | — | PASS |
| 2 | pytest discovers 'test_addition' function inside 'test_math.py' | pytest test collection shows 1 test found | — | PASS |
| 3 | pytest runs 'test_addition' function | Function executes: assert 2 + 3 == 5 | Check that 2 + 3 equals 5 | PASS |
| 4 | pytest reports test result | Test passed with no errors | Test result is PASS | PASS |
tests/ folder in a pytest project?tests/ folder helps keep the project clean and organized.tests/ is a best practice for clarity and maintenance.test_ or end with _test.py.test_example.py starts with test_, so pytest will find it automatically.project/
app.py
tests/
test_math.py
utils/
test_utils.py
Which files will pytest run by default when you run pytest in the project root?tests/ folder and all its subfolders for files starting with test_.test_math.py and test_utils.py match naming rules and are inside tests/ or its subfolder.test_sample.py inside tests/ folder:
def sample_test():
assert 1 + 1 == 2
When you run pytest, no tests are found. Why?test_.sample_test, which does not start with test_, so pytest ignores it.pytest.ini file helps customize test discovery and running specific groups of tests easily.Pass the test and this pattern moves unknown