有时只运行大型 doctests 文件的第一部分会很有用。
在代码更改后第一部分中断的情况有很多,我想只运行第一部分,直到它通过,然后再次运行整个文件。
我还没有找到一个简单的方法来做到这一点。
假设我用这个文件开始我的文档测试:
#!/usr/bin/env python
import doctest
doctest.testfile("scenario.rst")
而scenario.rst 看起来像这样:
>>> 'hello world'
'hello world'
>>> exit()
>>> 'this should not be processed anymore'
... lots of lines
>>> 'this should also not be processed'
在这个例子中,我使用 exit() 函数来演示我的意思,当然它不起作用,因为它被视为异常,doctest 很高兴地将其视为可以测试的东西的一部分:
**********************************************************************
File "_scenario.rst", line 10, in _scenario.rst
Failed example:
exit()
Exception raised:
Traceback (most recent call last):
File "c:\Python27\lib\doctest.py", line 1254, in __run
compileflags, 1) in test.globs
File "<doctest _scenario.rst[1]>", line 1, in <module>
exit()
File "c:\Python27\lib\site.py", line 372, in __call__
raise SystemExit(code)
SystemExit: None
**********************************************************************
File "_scenario.rst", line 12, in _scenario.rst
Failed example:
'this should not be processed anymore'
Expected nothing
Got:
'this should not be processed anymore'
**********************************************************************
1 items had failures:
2 of 3 in _scenario.rst
***Test Failed*** 2 failures.
那么这样一个doctest文件怎么会在中间被终止呢?
编辑:有 +SKIP 指令,但它只跳过一行。我需要一些跳过文件其余部分的东西。