0
0
PyTesttesting~5 mins

Test discovery rules in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ATestExample.py
Bexample_tested.py
Cexample.py
Dtest_example.py
Which function name will pytest recognize as a test inside a test file?
Acheck_function
Bfunction_test
Ctest_function
DTestFunction
Which class name will pytest consider for test discovery?
AsuiteTest
BTestSuite
Ctestsuite
DSuiteTest
How can you change the default test file pattern in pytest?
AEdit pytest.ini and set python_files
BRename files manually
CUse a different Python version
DChange function names
What happens if a test class has an __init__ method?
APytest will skip discovering tests inside it
BPytest will raise an error
CPytest will discover it normally
DPytest will run only __init__
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.