Recall & Review
beginner
What is a test package in pytest?
A test package is a directory containing multiple test modules and an __init__.py file, allowing pytest to discover and run tests organized in that directory.
Click to reveal answer
beginner
Why do we need an __init__.py file in a pytest test package?
The __init__.py file makes the directory a Python package, which helps pytest recognize it as a test package and allows importing modules within it.
Click to reveal answer
beginner
How does pytest discover tests inside a test package?
Pytest looks for files matching test_*.py or *_test.py inside the package directory and runs test functions or methods inside those files.
Click to reveal answer
intermediate
Can you organize tests in sub-packages inside a pytest test package?
Yes, you can create subdirectories with __init__.py files inside a test package to organize tests hierarchically, and pytest will discover tests recursively.
Click to reveal answer
intermediate
What is a practical benefit of using test packages in pytest?
Test packages help keep tests organized by feature or module, making it easier to maintain and run specific groups of tests without running everything.
Click to reveal answer
What file must be present in a directory for pytest to treat it as a test package?
✗ Incorrect
The __init__.py file marks the directory as a Python package, which pytest uses to recognize test packages.
Which file name pattern does pytest use to find test modules inside a test package?
✗ Incorrect
Pytest looks for files starting with test_ or ending with _test to find test modules.
Can pytest discover tests in subdirectories inside a test package?
✗ Incorrect
Subdirectories with __init__.py files are treated as sub-packages, allowing pytest to discover tests recursively.
What is the main advantage of organizing tests into packages?
✗ Incorrect
Organizing tests into packages helps keep tests structured and allows running specific groups of tests easily.
If a directory lacks __init__.py, what happens when pytest tries to discover tests there?
✗ Incorrect
Without __init__.py, the directory is not a package, so relative imports inside tests may fail, but pytest can still find tests by filename.
Explain how to create and organize a test package in pytest.
Think about Python packages and test discovery rules.
You got /4 concepts.
Describe the benefits of using test packages when writing tests with pytest.
Consider how grouping tests helps in real projects.
You got /4 concepts.