Bird
0
0

You have this test file named test_calc.py but pytest does not discover any tests inside it. What is the most likely reason?

medium📝 Debug Q14 of 15
PyTest - Test Organization
You have this test file named test_calc.py but pytest does not discover any tests inside it. What is the most likely reason?
AThe file name should be <code>calc_test.py</code>
BTest functions inside do not start with 'test_'
CPytest requires tests to be in the root folder only
DThe file is missing a main function
Step-by-Step Solution
Solution:
  1. Step 1: Recall pytest test discovery rules

    Pytest finds test functions only if their names start with 'test_'.
  2. Step 2: Identify why tests are not found

    If functions inside 'test_calc.py' don't start with 'test_', pytest ignores them.
  3. Final Answer:

    Test functions inside do not start with 'test_' -> Option B
  4. Quick Check:

    Function names must start with 'test_' [OK]
Quick Trick: Test functions must start with 'test_' [OK]
Common Mistakes:
MISTAKES
  • Renaming test files incorrectly
  • Thinking pytest needs a main function
  • Assuming tests must be in root folder

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes