Doctest
Examples in a docstring, written like an interactive session, can run as tests. doctest finds each line starting with >>>, runs it, and compares what it shows with the lines below. A documented example that has stopped being true then fails like any other test.
import doctest
def initials(name):
"""Return the capital initials.
>>> initials("ada lovelace")
'AL'
>>> initials("")
''
"""
words = name.split()
caps = [w[0].upper() for w in words]
return "".join(caps)
print(doctest.testmod())Errors and exact text
An expected exception is written as the line Traceback (most recent call last): followed by the exception line. doctest ignores the stack lines in between, so leave them out.
The comparison is on text, exactly: 'AL' is not "AL", and a float or a set printed differently fails. Keep examples short and deterministic. Run them with python -m doctest file.py, or with pytest --doctest-modules.
Your task
parse_duration(text) is written for you, without a docstring. Give it one with at least three examples: "1h30m", a minutes-only duration such as "45m", and the ValueError it raises for "soon".
The explanation opens here once every check passes.