Bird
0
0

Given a directory with files: test_alpha.py, alpha_test.py, testbeta.py, which files will pytest discover by default?

medium📝 Predict Output Q4 of 15
PyTest - Test Organization
Given a directory with files: test_alpha.py, alpha_test.py, testbeta.py, which files will pytest discover by default?
Atest_alpha.py and alpha_test.py only
Btest_alpha.py only
Calpha_test.py and testbeta.py only
DAll three files
Step-by-Step Solution
Solution:
  1. Step 1: Apply pytest file naming rules

    pytest discovers files starting with 'test_' or ending with '_test.py'.
  2. Step 2: Check each file

    'test_alpha.py' starts with 'test_', 'alpha_test.py' ends with '_test.py', 'testbeta.py' does not match either.
  3. Final Answer:

    test_alpha.py and alpha_test.py only -> Option A
  4. Quick Check:

    Files matching 'test_*' or '*_test.py' are discovered [OK]
Quick Trick: Files must start with 'test_' or end with '_test.py' [OK]
Common Mistakes:
MISTAKES
  • Including files without underscore after 'test'
  • Assuming any file with 'test' in name is discovered
  • Ignoring suffix '_test.py' pattern

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes