Challenge - 5 Problems
Test Function Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple pytest test function
What is the test result when running this pytest test function?
PyTest
def test_sum(): assert 2 + 3 == 5
Attempts:
2 left
💡 Hint
Check if the assertion condition is true.
✗ Incorrect
The assertion 2 + 3 == 5 is true, so the test passes without errors.
❓ assertion
intermediate2:00remaining
Identify the failing assertion in pytest
Which assertion will cause the pytest test to fail?
PyTest
def test_values(): assert 10 > 5 assert 'a' == 'b' assert [1, 2] == [1, 2]
Attempts:
2 left
💡 Hint
Check which condition is false.
✗ Incorrect
The assertion 'a' == 'b' is false, so pytest will fail at this line.
🔧 Debug
advanced2:00remaining
Find the error in this pytest test function
What error will pytest report when running this test function?
PyTest
def test_division(): result = 10 / 0 assert result == 0
Attempts:
2 left
💡 Hint
Consider what happens when dividing by zero in Python.
✗ Incorrect
Dividing by zero raises a ZeroDivisionError before the assertion runs.
❓ framework
advanced2:00remaining
pytest test discovery rules
Which function name will pytest automatically discover as a test?
Attempts:
2 left
💡 Hint
pytest looks for functions starting with a specific prefix.
✗ Incorrect
pytest discovers functions starting with test_ as tests.
🧠 Conceptual
expert2:00remaining
Effect of multiple assertions in one pytest test function
What happens when multiple assertions exist in one pytest test function and the first assertion fails?
Attempts:
2 left
💡 Hint
Think about how Python handles exceptions during test execution.
✗ Incorrect
When an assertion fails, it raises an exception stopping the test function immediately.