Bird
0
0

What is the correct way to name a Python file so that pytest recognizes it as a test module?

easy🧠 Conceptual Q11 of 15
PyTest - Test Organization
What is the correct way to name a Python file so that pytest recognizes it as a test module?
AThe file name can be anything as long as it contains tests.
BThe file name should start with <code>check_</code>.
CThe file name should be <code>pytest_module.py</code>.
DThe file name should start with <code>test_</code> or end with <code>_test.py</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest file naming conventions

    pytest automatically discovers test files if their names start with test_ or end with _test.py.
  2. Step 2: Evaluate each option

    Only The file name should start with test_ or end with _test.py. matches the correct naming pattern for pytest to find test modules automatically.
  3. Final Answer:

    The file name should start with test_ or end with _test.py. -> Option D
  4. Quick Check:

    pytest test file naming = start with test_ or end with _test.py [OK]
Quick Trick: Remember test files start with test_ or end with _test.py [OK]
Common Mistakes:
MISTAKES
  • Assuming any file with tests is recognized
  • Using incorrect prefixes like check_
  • Naming files without .py extension

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes