I have just started learning python and I am following some online lectures from my university. I have just been introduced to writing doctests in scripts. Below is my code:
""" Our first python source file. """
from operator import floordiv, mod
def divide_exact(n,d):
""" Return the quotient and remainder.
>>> q, r = divide_exact(2013, 10)
>>> q
201
>>> r
3
"""
return floordiv(n, d), mod(n, d)
When I run
python3 -m doctest -v lec3video3
I pass 0 testcases. I get this error
File "lec3video3test", line 7, in lec3video3test
Failed example:
q, r = divide_exact(2013, 10)
Exception raised:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/doctest.py", line 1329, in __run
compileflags, 1), test.globs)
File "<doctest lec3video3test[0]>", line 1, in <module>
q, r = divide_exact(2013, 10)
NameError: name 'divide_exact' is not defined
I don't know why because I know my code works. What am I doing wrong? I have tested my code in interactive mode and everything is correct.
IndentationError: unexpected indenton the first line of your code. Is that a typo? If I remove it, I'm not able to reproduce the issue. You need to make a minimal reproducible example.divide_exactdoes the exact same thing asdivmod, which is a Python builtin