如何处理python';医生考试?

如何处理python';医生考试?,python,testing,doctest,Python,Testing,Doctest,我有一个doctest,它在找不到文件时会出现IOError >>> configParser('conffig.ini') # should not exist Traceback (most recent call last): ... IOError: No such file: /homes/ndeklein/workspace/MS/PyMS/conffig.ini 但是,如果我想从另一台pc上测试它,或者其他人想测试它,路径不会是/homes/ndekle

我有一个doctest,它在找不到文件时会出现IOError

>>> configParser('conffig.ini') # should not exist
Traceback (most recent call last):
    ...
IOError: No such file: /homes/ndeklein/workspace/MS/PyMS/conffig.ini
但是,如果我想从另一台pc上测试它,或者其他人想测试它,路径不会是/homes/ndeklein/workspace/MS/PyMS/。我想做什么

>>> configParser('conffig.ini') # should not exist
Traceback (most recent call last):
    ...
IOError: No such file: os.path.abspath(conffig.ini)
但是因为它在docstring中,所以它会看到os.path.abspath(作为结果的一部分)


如何生成docstring测试变量的结果?

是否确实需要与路径名匹配?如果不需要,请使用省略号跳过输出的该部分:

>>> configParser('conffig.ini') # should not exist
Traceback (most recent call last):
    ...
IOError: No such file: ...
如果这样做,则需要捕获错误并手动测试值。类似于:

>>> try:
...   configParser('conffig.ini') # should not exist
... except IOError as e:
...   print('ok' if str(e).endswith(os.path.abspath('conffig.ini')) else 'fail')
ok

为什么要对磁盘上不存在的文件进行单元测试?有什么理由怀疑文件系统的正确性吗?