Challenge - 5 Problems
Assert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this pytest assertion?
Consider the following pytest test function. What will be the test result when running it?
PyTest
def test_sum(): result = sum([1, 2, 3]) assert result == 6
Attempts:
2 left
💡 Hint
Check if the sum of the list matches the asserted value.
✗ Incorrect
The sum of [1, 2, 3] is 6, which matches the assertion, so the test passes.
❓ assertion
intermediate2:00remaining
Which assertion correctly checks if a string contains a substring?
You want to assert that the string 'hello world' contains 'world'. Which assertion is correct?
Attempts:
2 left
💡 Hint
Use Python's membership operator for substring checks.
✗ Incorrect
Option D uses the correct syntax to check substring presence with 'in'. Option D is invalid syntax, C checks equality incorrectly, and D asserts the opposite.
🔧 Debug
advanced2:00remaining
Why does this pytest assertion fail?
Given the test below, why does it fail?
PyTest
def test_list_length(): items = [1, 2, 3] assert len(items) == 3
Attempts:
2 left
💡 Hint
Check the operator used in the assert statement.
✗ Incorrect
The assertion uses '=' which is assignment, not comparison. This causes a SyntaxError.
🧠 Conceptual
advanced2:00remaining
What happens if an assertion fails in pytest?
In pytest, when an assert statement fails inside a test function, what is the outcome?
Attempts:
2 left
💡 Hint
Think about how pytest handles failed assertions.
✗ Incorrect
Pytest marks the test as failed and shows the AssertionError details when an assert fails.
❓ framework
expert2:00remaining
Which pytest feature helps to show detailed info on assert failures automatically?
You want pytest to show detailed values in assert failure messages without writing custom messages. Which feature enables this?
Attempts:
2 left
💡 Hint
This feature modifies assert statements to provide better failure details.
✗ Incorrect
Pytest rewrites assert statements to show detailed info on failure automatically, called assert rewriting.