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
More on Testing, services & metrics
Why should automation scripts have tests at all?BeginnerWhy does pytest use plain `assert` instead of `assertEqual`?BeginnerWhat are pytest fixtures, and what scopes exist?IntermediateWhat built-in fixtures do you use most?IntermediateHow does `@pytest.mark.parametrize` work?BeginnerWhat is moto, and how do you use it with pytest?Intermediate