0
0
PyTesttesting~20 mins

Test file and function naming conventions in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pytest Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Identify valid pytest test file names
Which of the following file names will pytest automatically recognize as test files when running tests?
Atest_math.py, utils.py, helpers_test.py
Bmath_test.py, utils.py, test_helpers.py
Cmath.py, utils.py, helpers.py
Dtest_math.py, test_utils.py, math_test.py
Attempts:
2 left
💡 Hint
pytest looks for files starting with 'test_' or ending with '_test.py'.
🧠 Conceptual
intermediate
2:00remaining
Identify valid pytest test function names
Which function names will pytest recognize as test functions inside a test file?
Atest_addition, check_subtraction, test_multiplication
Badd_test, subtract_test, multiply_test
Ctest_addition, test_subtraction, test_multiplication
Daddition_test, test_subtraction, multiplication_test
Attempts:
2 left
💡 Hint
pytest looks for functions starting with 'test'.
assertion
advanced
2:00remaining
Assertion failure due to incorrect test function name
Given the following test file named test_math.py with these functions, which function will NOT run during pytest execution?
PyTest
def test_add():
    assert 1 + 1 == 2

def check_subtract():
    assert 2 - 1 == 1

def test_multiply():
    assert 2 * 3 == 6
Acheck_subtract
BAll functions run
Ctest_multiply
Dtest_add
Attempts:
2 left
💡 Hint
pytest only runs functions starting with 'test'.
🔧 Debug
advanced
2:00remaining
Debug why pytest does not find tests in a file
You have a file named mathTests.py with functions named test_add and test_subtract. When running pytest, no tests are found. What is the most likely reason?
AFunction names do not start with 'test'
BFile name does not start with 'test_' or end with '_test.py'
CFunctions are missing assert statements
Dpytest is not installed
Attempts:
2 left
💡 Hint
pytest discovers test files by their names.
framework
expert
3:00remaining
Best practice for organizing pytest test files and functions
Which of the following is the best practice for naming pytest test files and functions to ensure automatic discovery and clear organization?
AName test files starting with 'test_' and test functions starting with 'test_', use descriptive names for both
BName test files with any name, but test functions must start with 'test_'
CName test files ending with '_test.py' but test functions can have any name
DName test files and functions with any names as long as they are in a 'tests' folder
Attempts:
2 left
💡 Hint
pytest discovers tests based on file and function name patterns.