Nudelsuppe
Nudelsuppe

Reputation: 157

Python 3/Doctest: Exception is not evaluated as expected result

I have a python module containing (amongst other functions) this piece of code:

def check_color_range(*argv):
"""
Abbreviated documentation and other tests.

>>> check_color_range(23, -1, 99, 10000)
Traceback (most recent call last):
    ...
TypeError: Falscher Farbwert -1!    
"""
for c in argv:
    if c < 0 or c > 255:
        raise TypeError('Falscher Farbwert ' + str(c) + '!')

When I run this using doctest like so: python -m doctest -v demo.py, I get the following output:

Trying:
    check_color_range(23, -1, 99, 10000)
Expecting:
    Traceback (most recent call last):
        ...
    TypeError: Falscher Farbwert -1!
**********************************************************************
File "C:\az\code_camp_python\src\EigeneProgramme\Tag3\arcade_base\demo.py", line 5, in demo.check_color_range
Failed example:
    check_color_range(23, -1, 99, 10000)
Expected:
    Traceback (most recent call last):
        ...
    TypeError: Falscher Farbwert -1!
Got:
    Traceback (most recent call last):
      File "C:\az\miniconda3\envs\py37\lib\doctest.py", line 1329, in __run
        compileflags, 1), test.globs)
      File "<doctest demo.check_color_range[0]>", line 1, in <module>
        check_color_range(23, -1, 99, 10000)
      File "C:\az\code_camp_python\src\EigeneProgramme\Tag3\arcade_base\demo.py", line 12, in check_color_range
        raise TypeError('Falscher Farbwert ' + str(c) + '!')
    TypeError: Falscher Farbwert -1!
1 items had no tests:
    demo
**********************************************************************
1 items had failures:
   1 of   1 in demo.check_color_range
1 tests in 2 items.
0 passed and 1 failed.
***Test Failed*** 1 failures.

For me the expected and the actual Errors look the same, but I may be missing something. I already compared whitespace etc., which seems to be the same.

I then tried to paste the complete Traceback from the "Got:" section into the testcase - and I'm still get the failed test, so I guess I must be doing something wrong.

I'd be very happy, if you could give me a heads-up.

Upvotes: 1

Views: 417

Answers (1)

DrKaoliN
DrKaoliN

Reputation: 1402

On line 8 you have: TypeError: Falscher Farbwert -1!____ (4 blank spaces at the end)

You should replace it with: TypeError: Falscher Farbwert -1!

Upvotes: 1

Related Questions