Bird
0
0

How can you rename the file to follow pytest discovery rules without changing function names?

hard🚀 Application Q15 of 15
PyTest - Test Organization
You want pytest to discover tests in a file named mytests.py containing functions def test_one(): and def test_two():. By default, pytest does not find this file. How can you rename the file to follow pytest discovery rules without changing function names?
ARename to my_test_s.py
BRename to mytestsTest.py
CRename to testmytests.py
DRename to test_mytests.py
Step-by-Step Solution
Solution:
  1. Step 1: Recall pytest file discovery naming

    pytest finds files starting with 'test_' or ending with '_test.py'.
  2. Step 2: Check options for correct naming

    'test_mytests.py' starts with 'test_' [check]. 'mytestsTest.py' ends with 'Test.py' (uppercase 'T' not matching lowercase 'test'). 'testmytests.py' lacks '_' after 'test'. 'my_test_s.py' does not start with 'test_' or end with '_test.py'. Only the first option works.
  3. Final Answer:

    Rename to test_mytests.py -> Option D
  4. Quick Check:

    File starts or ends with 'test' = test_mytests.py [OK]
Quick Trick: File must start or end with 'test' exactly [OK]
Common Mistakes:
MISTAKES
  • Removing 'test' from file name
  • Adding 'test' inside word without underscore
  • Using camelCase instead of snake_case

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes