Bird
0
0

You have a test file named TestExample.py with a function def test_func():. pytest does not run this test. What is the likely cause?

medium📝 Debug Q14 of 15
PyTest - Test Organization
You have a test file named TestExample.py with a function def test_func():. pytest does not run this test. What is the likely cause?
AFunction name does not start with 'test_'
Bpytest requires test classes to run tests
CFile name does not follow pytest discovery rules
DFunction is missing a return statement
Step-by-Step Solution
Solution:
  1. Step 1: Check pytest file discovery rules

    pytest finds files starting or ending with 'test' in lowercase and ending with '.py'. 'TestExample.py' starts with uppercase 'T', so it is not recognized.
  2. Step 2: Verify function name and other options

    Function name 'test_func' is correct. Return statement is not required. pytest does not require test classes to run functions.
  3. Final Answer:

    File name does not follow pytest discovery rules -> Option C
  4. Quick Check:

    File name case-sensitive for discovery = D [OK]
Quick Trick: File names must be lowercase starting or ending with 'test' [OK]
Common Mistakes:
MISTAKES
  • Ignoring case sensitivity in file names
  • Thinking function needs return statement
  • Assuming test classes are mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes