Bird
0
0

A test package folder has an __init__.py file with syntax errors. What will pytest do when discovering tests?

medium📝 Debug Q7 of 15
PyTest - Test Organization
A test package folder has an __init__.py file with syntax errors. What will pytest do when discovering tests?
AFail with ImportError and stop test discovery in that package.
BIgnore the __init__.py file and run tests anyway.
CRun tests but skip any test functions in __init__.py.
DAutomatically fix the syntax errors and continue.
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest import behavior

    pytest imports __init__.py files to recognize packages; syntax errors cause import failure.
  2. Step 2: Consequence of syntax errors

    ImportError stops pytest from loading that package, so tests inside are not discovered.
  3. Final Answer:

    Fail with ImportError and stop test discovery in that package. -> Option A
  4. Quick Check:

    Syntax error in __init__.py = ImportError [OK]
Quick Trick: Syntax errors in __init__.py block pytest test discovery [OK]
Common Mistakes:
MISTAKES
  • Assuming pytest ignores __init__.py errors
  • Thinking pytest auto-fixes syntax errors
  • Believing tests run despite import errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes