Editor

Fix the Failing Test

Beginner · Fix the bug · from Python Testing with pytest: Write Tests That Actually Help

From the lesson: Python Testing with pytest: Write Tests That Actually Help

Imagine you wrote a spell-checker. It works great on the word "hello." But what about "HeLLo"? Or an empty string? Or a number? You won't know until something breaks - unless you write tests.

Read the lesson

The function is_adult is supposed to return True if age is 18 or older, and False otherwise. The tests are correct, but the function has a bug. Fix the function so all tests pass, then print All tests passed!.

def is_adult(age):
return age > 18 # Bug is here!
def test_is_adult():
assert is_adult(18) == True
assert is_adult(21) == True
assert is_adult(17) == False
assert is_adult(0) == False
test_is_adult()
print('All tests passed!')

More pytest exercises

All Python exercises · 50 practice problems · Testing quiz