Doctest returning failure, yet “Expected” and “Got” match perfectly

我只是一个虾纸丫 提交于 2019-12-07 09:23:09

问题


I'm trying to do the second exercise in the Lists section of the book "How to Think Like a Computer Scientist". I basically have to match the given "doctest" with a program of my own that returns no error. I tried several ways, but despite the fact that the "Got" matches the "Expected" perfectly, it keeps giving me 1 failure.

I already saw one question here that asked "How can python 2 doctest fail and yet have no difference in values in the failure message?" I tried a few of the solutions given, like changing the test to "raw" by putting the r before it, but I don't think that the answer matches my case, because I checked several times after seeing this question and there isn´t a visible extra space where the problem seems to be.

This is the test I'm supposed to match:

"""
  >>> b_list[1:]
  ['Stills', 'Nash']
  >>> group = b_list + c_list
  >>> group[-1]
  'Young'
"""

And this is the program I wrote:

# Add your doctests here:
"""
    >>> b_list[1:]
    ['Stills', 'Nash'] 
    >>> group = b_list + c_list
    >>> group[-1]
    'Young'
"""
#Write your python code here:
b_list = ['a', 'Stills', 'Nash']
b_list[1:]
c_list = ['Young']
group = b_list + c_list
group[-1]

if __name__ == '__main__':
    import doctest 
    doctest.testmod()

And this is the test result:

File ".\ch902.py", line 3, in __main__

Failed example:

    b_list[1:]

Expected:

    ['Stills', 'Nash']

Got:

    ['Stills', 'Nash']
**********************************
1 items had failures:
   1 of   3 in __main__
***Test Failed*** 1 failures.

来源:https://stackoverflow.com/questions/38678709/doctest-returning-failure-yet-expected-and-got-match-perfectly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!