0
0
PyTesttesting~5 mins

Conftest.py purpose in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main purpose of conftest.py in pytest?

conftest.py is used to share fixtures and hooks across multiple test files without importing them explicitly.

Click to reveal answer
beginner
How does pytest find and use conftest.py files?

pytest automatically discovers conftest.py files in test directories and applies their fixtures and hooks to tests in the same or subdirectories.

Click to reveal answer
beginner
Can you import <code>conftest.py</code> directly in your test files?
<p>No, you should not import <code>conftest.py</code> directly. pytest loads it automatically to provide fixtures and hooks.</p>
Click to reveal answer
beginner
What kind of code do you typically put inside conftest.py?

You put reusable fixtures, hooks, and configuration code that multiple test files can use to avoid repetition.

Click to reveal answer
intermediate
Why is using conftest.py better than importing fixtures manually?

It keeps tests cleaner and simpler by avoiding manual imports and allows pytest to manage fixture scope and sharing automatically.

Click to reveal answer
What does conftest.py mainly provide in pytest?
ATest data files
BTest case definitions
CTest reports
DShared fixtures and hooks
Should you import conftest.py in your test files?
ANo, pytest loads it automatically
BYes, always
COnly for fixtures
DOnly for hooks
Where does pytest look for conftest.py files?
AOnly in the root directory
BIn the Python standard library
CIn test directories and subdirectories
DIn the user's home directory
What kind of code is NOT suitable for conftest.py?
ATest case functions
BReusable fixtures
CHooks for pytest events
DConfiguration code
Using conftest.py helps to:
ARun tests in parallel
BAvoid repeating fixture code
CGenerate test reports
DWrite test cases faster
Explain the role of conftest.py in organizing pytest tests.
Think about how pytest finds and uses shared setup code.
You got /4 concepts.
    Describe what kind of code you would put inside conftest.py and why.
    Consider what helps tests run smoothly and share setup.
    You got /4 concepts.