Bird
0
0

Given this folder structure:

medium📝 Predict Output Q13 of 15
PyTest - Test Organization
Given this folder structure:
tests/
  __init__.py
  test_math.py
  test_string.py
What will happen when you run pytest tests/?
Apytest will skip all tests because folder has __init__.py
Bpytest will run only <code>test_math.py</code> tests
Cpytest will raise an error because <code>__init__.py</code> is present
Dpytest will run all tests in both <code>test_math.py</code> and <code>test_string.py</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest test discovery in packages

    pytest finds and runs all test files inside a test package folder when you run pytest on that folder.
  2. Step 2: Effect of __init__.py on test discovery

    The presence of __init__.py marks the folder as a package but does not prevent pytest from running tests inside.
  3. Final Answer:

    pytest will run all tests in both test_math.py and test_string.py -> Option D
  4. Quick Check:

    pytest runs all tests in package folder = D [OK]
Quick Trick: pytest runs all tests in package folder with __init__.py [OK]
Common Mistakes:
MISTAKES
  • Thinking __init__.py blocks test discovery
  • Assuming only one test file runs
  • Expecting errors due to __init__.py presence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes