conftest.py
noun
say it: “KON-test dot PIE” /ˈkɑnˌtɛst dɑt ˈpaɪ/
A file that pytest reads first, holding setup that every test in its folder shares.
What is conftest.py?
conftest.py is a file pytest reads before it runs the tests in its folder and the folders inside it. It holds the set-up every one of those tests shares, such as fixtures or choosing matplotlib's Agg backend, so no test file repeats it.
# tests/conftest.py
import matplotlib
matplotlib.use("Agg") # every chart test in this folder draws with no window
In a sentence
- “The Agg setting lives in conftest.py, so no test file repeats it.”
- “pytest read conftest.py before any test in the folder ran.”
Level: Journeyman · More Python terms at this level
Updated