ich habe gerade ein Problem mit doctests. Ich definiere eine Funktion, die einen Generator zurückliefern soll.
Code: Alles auswählen
import os
def scanfolder(dst):
"""scan the given folder, return a list of all files
dst must be a valid folder
>>> scanfolder('a_folder_that_doesn_t_exist')
Traceback (most recent call last):
...
IOError: the specified folder does not exist
return a generator
>>> g = scanfolder("/home")
>>> print g
<generator object ...>
"""
if not os.path.isdir(dst):
raise IOError, "the specified folder does not exist"
for root, dirs, files in os.walk(dst):
for file in files:
yield os.path.join(root, file)
if __name__ == '__main__':
import doctest
doctest.testmod(optionflags=doctest.ELLIPSIS)
Mache ich was falsch oder kann man sowas mit doctests nicht richtig prüfen?Failed example:
scanfolder('a_folder_that_doesn_t_exist')
Expected:
Traceback (most recent call last):
...
IOError: the specified folder does not exist
Got:
<generator object at 0xb7a56f2c>
**********************************************************************
1 items had failures:
1 of 3 in __main__.scanfolder
***Test Failed*** 1 failures.