0
0
PyTesttesting~5 mins

Test file and function naming conventions in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
Why should test files in pytest start with test_?
Pytest automatically discovers test files that start with test_ or end with _test.py. This naming helps pytest find and run your tests without extra configuration.
Click to reveal answer
beginner
What is the recommended naming pattern for test functions in pytest?
Test functions should start with test_. For example, def test_addition():. This allows pytest to recognize and run them as tests.
Click to reveal answer
beginner
Can you name a test file calculator.py and expect pytest to run tests inside it automatically?
No. Pytest will not discover tests in files without the test_ prefix or _test.py suffix. The file should be named like test_calculator.py.
Click to reveal answer
beginner
What happens if a test function does not start with test_ in pytest?
Pytest will ignore the function because it does not match the naming pattern for test functions. Only functions starting with test_ are run as tests.
Click to reveal answer
beginner
Why is consistent naming important in test files and functions?
Consistent naming helps pytest find tests automatically, keeps your project organized, and makes it easier for others to understand and run your tests.
Click to reveal answer
Which of these is a valid pytest test file name?
Atest_math.py
Bmath_tested.py
Cmath.py
Dtesting_math.py
How should you name a test function for pytest to recognize it?
Atest_addition()
Baddition_test()
Ccheck_addition()
DAddTest()
If a test file is named calculator.py, what will pytest do?
ARun all tests inside it
BIgnore it during test discovery
CRun tests only if specified manually
DRename it automatically
What prefix should test functions have in pytest?
Acheck_
Bverify_
Cassert_
Dtest_
Why is it important to follow naming conventions in pytest?
ATo reduce code size
BTo make tests run faster
CTo allow pytest to find and run tests automatically
DTo avoid writing assertions
Explain the naming conventions for test files and test functions in pytest and why they matter.
Think about how pytest finds tests without manual configuration.
You got /4 concepts.
    What happens if you name a test function without the 'test_' prefix in pytest?
    Consider how pytest identifies test functions.
    You got /3 concepts.