Challenge - 5 Problems
Pytest Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Identify valid pytest test file names
Which of the following file names will pytest automatically recognize as test files when running tests?
Attempts:
2 left
💡 Hint
pytest looks for files starting with 'test_' or ending with '_test.py'.
✗ Incorrect
pytest automatically discovers test files that start with test_ or end with _test.py. Option D lists files that follow these conventions.
🧠 Conceptual
intermediate2:00remaining
Identify valid pytest test function names
Which function names will pytest recognize as test functions inside a test file?
Attempts:
2 left
💡 Hint
pytest looks for functions starting with 'test'.
✗ Incorrect
pytest recognizes functions that start with test as test functions. Option C has all functions starting with test.
❓ assertion
advanced2: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
Attempts:
2 left
💡 Hint
pytest only runs functions starting with 'test'.
✗ Incorrect
pytest runs only functions whose names start with test. The function check_subtract does not start with test, so it will not run.
🔧 Debug
advanced2: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?Attempts:
2 left
💡 Hint
pytest discovers test files by their names.
✗ Incorrect
pytest discovers test files only if their names start with test_ or end with _test.py. The file mathTests.py does not follow this convention, so pytest ignores it.
❓ framework
expert3: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?
Attempts:
2 left
💡 Hint
pytest discovers tests based on file and function name patterns.
✗ Incorrect
Best practice is to name test files starting with test_ or ending with _test.py and test functions starting with test_. Using descriptive names helps clarity and maintenance.