1
我有一個doctest,當文件沒有找到時,它需要IOError。如何處理python的doctest中的變量錯誤?
>>> configParser('conffig.ini') # should not exist
Traceback (most recent call last):
...
IOError: No such file: /homes/ndeklein/workspace/MS/PyMS/conffig.ini
但是,如果我想從不同的PC測試,或者其他人想要測試它,路徑不會是/家庭/ ndeklein /工作區/ MS/PyMS /。我願意這樣做
>>> configParser('conffig.ini') # should not exist
Traceback (most recent call last):
...
IOError: No such file: os.path.abspath(conffig.ini)
,而是因爲它是在文檔字符串它認爲os.path.abspath將(作爲結果的一部分。
我怎樣才能讓文檔字符串測試變量的結果?
爲什麼您要測試磁盤上文件的非阻力?有沒有理由懷疑文件系統的正確性? – SingleNegationElimination 2012-03-05 14:48:27