Bird
0
0

When you execute pytest in a directory without specifying any files or options, what does pytest do by default?

easy🧠 Conceptual Q1 of 15
PyTest - Basics and Setup
When you execute pytest in a directory without specifying any files or options, what does pytest do by default?
AIt runs only the tests defined in <code>test_main.py</code> if it exists.
BIt discovers and runs all test files matching the pattern <code>test_*.py</code> or <code>*_test.py</code> in the current directory and subdirectories.
CIt runs no tests and only shows the pytest version.
DIt runs all Python files in the directory regardless of naming.
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest discovery

    By default, pytest looks for test files matching test_*.py or *_test.py patterns.
  2. Step 2: Recursive search

    It recursively searches the current directory and subdirectories for such files.
  3. Step 3: Runs all discovered tests

    All tests found in those files are executed.
  4. Final Answer:

    It discovers and runs all test files matching the pattern test_*.py or *_test.py in the current directory and subdirectories. -> Option B
  5. Quick Check:

    Default pytest runs all matching test files recursively [OK]
Quick Trick: pytest auto-discovers tests in test_*.py files recursively [OK]
Common Mistakes:
MISTAKES
  • Assuming pytest runs only tests in the current directory without recursion.
  • Thinking pytest runs all Python files regardless of naming.
  • Believing pytest runs no tests without explicit file arguments.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes