Recall & Review
beginner
What is a test module in pytest?
A test module is a Python file that contains test functions or classes. Pytest automatically finds and runs tests inside these modules.
Click to reveal answer
beginner
How should you name a test module for pytest to recognize it automatically?
Name the file starting with
test_ or ending with _test.py. For example, test_example.py or example_test.py.Click to reveal answer
beginner
Why is it important to keep test modules separate from application code?
Separating test modules helps keep code organized, makes tests easier to find, and prevents accidental execution of tests in production.
Click to reveal answer
intermediate
What is the role of
__init__.py in test directories?In pytest,
__init__.py files are optional. They can make test directories into packages but are not required for pytest to discover tests.Click to reveal answer
beginner
How can you run tests from a specific test module using pytest?
Use the command
pytest path/to/test_module.py. This runs all tests inside that module only.Click to reveal answer
Which file name will pytest automatically recognize as a test module?
✗ Incorrect
Pytest recognizes files starting with 'test_' or ending with '_test.py'. 'test_math.py' fits this pattern.
What does pytest look for inside a test module to run tests?
✗ Incorrect
Pytest runs functions or methods whose names start with 'test' inside test modules.
If you want to run tests only from a single test module, what command do you use?
✗ Incorrect
Running 'pytest test_module.py' runs tests only from that file.
Is it necessary to have an __init__.py file in a test directory for pytest to find tests?
✗ Incorrect
Pytest can discover tests without __init__.py files in test directories.
Why should test modules be kept separate from application code?
✗ Incorrect
Separating test modules helps keep code organized and prevents accidental test runs in production.
Explain how pytest discovers and runs tests inside test modules.
Think about file names, function names, and how pytest finds tests.
You got /4 concepts.
Describe best practices for organizing test modules in a Python project using pytest.
Consider how to keep tests easy to find and run.
You got /4 concepts.