Bird
0
0

Why does pytest automatically discover tests without explicit test suites or main functions?

hard🧠 Conceptual Q10 of 15
PyTest - Basics and Setup
Why does pytest automatically discover tests without explicit test suites or main functions?
ABecause pytest requires tests to be registered manually
BBecause pytest uses naming conventions and introspection to find tests
CBecause pytest only runs tests defined in __main__
DBecause pytest uses XML configuration files to list tests
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest test discovery mechanism

    Pytest finds tests by looking for files and functions matching naming patterns using introspection.
  2. Step 2: Eliminate incorrect options

    Pytest does not require manual registration, does not run only __main__, and does not rely on XML files for discovery.
  3. Final Answer:

    Because pytest uses naming conventions and introspection to find tests -> Option B
  4. Quick Check:

    Test discovery = naming + introspection [OK]
Quick Trick: pytest finds tests by name and introspection automatically [OK]
Common Mistakes:
MISTAKES
  • Thinking tests must be registered manually
  • Assuming tests run only in main module
  • Believing XML files control test discovery

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes