Bird
0
0

A test file named 'test_example.py' contains a function 'def example_test()'. Will pytest run this function by default?

medium📝 Debug Q6 of 15
PyTest - Test Organization
A test file named 'test_example.py' contains a function 'def example_test()'. Will pytest run this function by default?
AYes, because function name ends with '_test'
BYes, because the file name starts with 'test_'
CNo, because function name does not start with 'test'
DNo, unless the function is decorated with @pytest.mark.test
Step-by-Step Solution
Solution:
  1. Step 1: Recall pytest function naming rules

    pytest runs functions starting with 'test' by default.
  2. Step 2: Check function name 'example_test'

    It ends with '_test' but does not start with 'test', so it is not run.
  3. Final Answer:

    No, because function name does not start with 'test' -> Option C
  4. Quick Check:

    Function must start with 'test' to run [OK]
Quick Trick: Function names must start with 'test' to run by default [OK]
Common Mistakes:
MISTAKES
  • Assuming suffix '_test' triggers discovery
  • Thinking file name alone runs all functions
  • Believing decorators are needed for default discovery

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes