Bird
0
0

You have a test file named math_test.py with a function named add_test(). When running pytest, no tests are found. What is the most likely cause?

medium📝 Debug Q14 of 15
PyTest - Basics and Setup
You have a test file named math_test.py with a function named add_test(). When running pytest, no tests are found. What is the most likely cause?
AThe function name does not start with 'test_'
BThe file extension is incorrect
CThe file name does not start with 'test_'
DThe test function has no assert statement
Step-by-Step Solution
Solution:
  1. Step 1: Check file naming

    The file math_test.py ends with _test.py, which is valid for pytest discovery.
  2. Step 2: Check function naming

    The function is named add_test(), which does not start with test_. Pytest ignores such functions.
  3. Final Answer:

    The function name does not start with 'test_' -> Option A
  4. Quick Check:

    Function must start with 'test_' = C [OK]
Quick Trick: Function names must start with 'test_' to be found [OK]
Common Mistakes:
MISTAKES
  • Assuming file name alone is enough
  • Naming functions with '_test' suffix instead of prefix
  • Forgetting to add assert statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes