Bird
0
0

Which folder structure will pytest recognize as a test package?

easy🧠 Conceptual Q2 of 15
PyTest - Test Organization
Which folder structure will pytest recognize as a test package?
Atests/\n __init__.py\n test_example.py
Btests/\n test_example.py
Ctests/\n __init__.txt\n test_example.py
Dtests/\n example.py
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct package marker

    Only __init__.py marks a folder as a Python package recognized by pytest.
  2. Step 2: Check folder contents

    tests/\n __init__.py\n test_example.py has __init__.py and a test file, so pytest treats it as a test package.
  3. Final Answer:

    tests/ with __init__.py and test_example.py -> Option A
  4. Quick Check:

    __init__.py presence = test package [OK]
Quick Trick: Only __init__.py files mark test packages, not other extensions [OK]
Common Mistakes:
MISTAKES
  • Using __init__.txt instead of __init__.py
  • Assuming test files alone create a package
  • Ignoring the need for __init__.py in subfolders

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes