Bird
0
0

You want pytest to automatically discover and run tests in your project. Which combination of file and function names will ensure this?

hard🚀 Application Q15 of 15
PyTest - Basics and Setup
You want pytest to automatically discover and run tests in your project. Which combination of file and function names will ensure this?
  • File: example_test.py
  • Functions: test_case1(), case2_test(), test_case3()
Which functions will pytest run?
ANone of the functions
BOnly <code>case2_test()</code>
CAll three functions
DOnly <code>test_case1()</code> and <code>test_case3()</code>
Step-by-Step Solution
Solution:
  1. Step 1: Confirm file naming

    The file example_test.py ends with _test.py, so pytest will discover it.
  2. Step 2: Check function naming rules

    Pytest runs functions starting with test_. So test_case1() and test_case3() will run. case2_test() will be ignored.
  3. Final Answer:

    Only test_case1() and test_case3() -> Option D
  4. Quick Check:

    Functions start with 'test_' run = D [OK]
Quick Trick: File ends '_test.py'; functions start 'test_' to run [OK]
Common Mistakes:
MISTAKES
  • Thinking '_test' suffix in function name triggers test
  • Assuming all functions in test files run automatically
  • Confusing file and function naming rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes