Bird
0
0

You have nested test directories: 'tests/unit' and 'tests/integration'. How can you run only the tests in 'tests/integration' using pytest discovery rules?

hard🚀 Application Q9 of 15
PyTest - Test Organization
You have nested test directories: 'tests/unit' and 'tests/integration'. How can you run only the tests in 'tests/integration' using pytest discovery rules?
ARename 'tests/integration' to 'integration_tests'
BUse '-k integration' option to filter tests
CSet 'testpaths = tests/integration' in pytest.ini
DRun pytest with the path 'tests/integration' as argument
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest path argument

    pytest runs tests only in the specified directory if given a path.
  2. Step 2: Apply correct command

    Running 'pytest tests/integration' runs tests only in that folder.
  3. Final Answer:

    Run pytest with the path 'tests/integration' as argument -> Option D
  4. Quick Check:

    Specify directory path to run tests there [OK]
Quick Trick: Pass directory path to pytest to run tests there [OK]
Common Mistakes:
MISTAKES
  • Using '-k integration' filters test names, not directories
  • Renaming directories is unnecessary
  • Setting 'testpaths' limits discovery but does not run selectively

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes