How to Run Pytest Effectively in CI with Logging, Markers, and Coverage
A technical guide outlines best practices for running Pytest in production and CI environments, focusing on logging, test categorization, and code coverage. Developers can use flags like --log-cli-level and --color=yes for clearer output, and the caplog fixture to assert on specific log messages within tests. Pytest markers allow teams to separate fast unit tests from slower integration tests that require external resources like AWS, preventing CI failures when those environments are unavailable. An autouse fixture in conftest.py can automatically skip integration tests unless a specific environment variable is set, adding a safety net beyond manual filtering. The guide also recommends using pytest-cov to measure code coverage, while cautioning that high coverage percentages do not guarantee correctness if test assertions are weak.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in