Bird
0
0

You want to organize tests in multiple files but only want pytest to run tests in files starting with test_. Which naming pattern should you use for other Python files containing helper functions?

hard🚀 Application Q8 of 15
PyTest - Basics and Setup
You want to organize tests in multiple files but only want pytest to run tests in files starting with test_. Which naming pattern should you use for other Python files containing helper functions?
Ahelper_utils.py
Btest_helpers.py
Chelpers_test.py
Dtest_helper_utils.py
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest file discovery

    Pytest runs tests only in files starting with test_ or ending with _test.py.
  2. Step 2: Choose helper file name to exclude tests

    To exclude files from test discovery, name them without test_ prefix or suffix, e.g., helper_utils.py.
  3. Final Answer:

    helper_utils.py -> Option A
  4. Quick Check:

    Helper files should NOT start or end with 'test_' [OK]
Quick Trick: Helper files avoid 'test_' prefix/suffix to skip test discovery [OK]
Common Mistakes:
MISTAKES
  • Naming helper files with 'test_' prefix
  • Expecting pytest to skip files ending with '_test.py'
  • Mixing test and helper code in same file

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes