Bird
0
0

You run pytest test_example.py but get an error: ModuleNotFoundError: No module named 'example'. What is the most likely cause?

medium📝 Debug Q6 of 15
PyTest - Basics and Setup
You run pytest test_example.py but get an error: ModuleNotFoundError: No module named 'example'. What is the most likely cause?
AThe test file imports a module named 'example' which is missing or not installed.
BPytest command syntax is incorrect; it should be <code>pytest -m test_example.py</code>.
CThe test file name is invalid; pytest requires files to start with 'test_'.
DPytest cannot run tests in files with underscores.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the error message

    ModuleNotFoundError means Python cannot find a module that the test file tries to import.
  2. Step 2: Check command and file naming

    The command and file name are valid; pytest supports underscores and the syntax is correct.
  3. Final Answer:

    The test file imports a module named 'example' which is missing or not installed. -> Option A
  4. Quick Check:

    ModuleNotFoundError means missing import module [OK]
Quick Trick: ModuleNotFoundError means missing or misnamed import [OK]
Common Mistakes:
MISTAKES
  • Thinking pytest command syntax is wrong
  • Assuming file naming causes import errors
  • Believing pytest cannot handle underscores

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes