Recall & Review
beginner
What is test discovery in pytest?
Test discovery is the process pytest uses to find test files and test functions automatically before running them.
Click to reveal answer
beginner
How does pytest identify test files by default?
Pytest looks for files matching the pattern
test_*.py or *_test.py in the current directory and subdirectories.Click to reveal answer
beginner
What naming convention does pytest use to find test functions inside test files?
Pytest finds test functions that start with
test_ inside test files.Click to reveal answer
intermediate
Can pytest discover tests inside classes? If yes, what is the rule?
Yes, pytest discovers test methods inside classes that start with
Test and do not have an __init__ method. Test methods must start with test_.Click to reveal answer
intermediate
How can you customize test discovery patterns in pytest?
You can customize test discovery by configuring
python_files, python_functions, and python_classes in pytest.ini or other config files, or by using command-line options like --pyargs.Click to reveal answer
Which file name will pytest discover by default?
✗ Incorrect
Pytest discovers files starting with 'test_' or ending with '_test.py'. 'test_example.py' matches this pattern.
Which function name will pytest recognize as a test inside a test file?
✗ Incorrect
Pytest looks for functions starting with 'test_' as test functions.
Which class name will pytest consider for test discovery?
✗ Incorrect
Pytest discovers classes starting with 'Test' for test methods.
How can you change the default test file pattern in pytest?
✗ Incorrect
You can configure 'python_files' in pytest.ini to change which files pytest discovers.
What happens if a test class has an __init__ method?
✗ Incorrect
Pytest skips test classes that define an __init__ method.
Explain how pytest discovers test files and test functions by default.
Think about file and function naming conventions.
You got /3 concepts.
Describe how to customize test discovery rules in pytest using configuration files.
Look into pytest configuration options.
You got /3 concepts.