Interview Prep/Python for DevOps/Testing, services & metrics

How does pytest discover and run tests?

BeginnerConceptTesting, services & metrics
Answer

By default pytest collects files named test_*.py or *_test.py, functions named test_*, and methods named test_* in classes named Test* (without __init__). Configuration lives in pyproject.toml under [tool.pytest.ini_options] (testpaths, addopts, markers).

pytest -q                      # quiet
pytest tests/test_checks.py::test_open_ssh_is_high -vv
pytest -k "snapshot and not slow" -x --lf    # filter, stop at first failure, last-failed
pytest --cov=cloudaudit --cov-report=term-missing
All Python for DevOps questions Roadmap: Python for automation

More on Testing, services & metrics