[svn r38122] fix parsing of extra lines (to be executed)

--HG--
branch : trunk
This commit is contained in:
hpk 2007-02-07 22:31:13 +01:00
parent 461c0b6a54
commit 7213771cc9
2 changed files with 16 additions and 0 deletions

View File

@ -74,6 +74,7 @@ class DoctestText(py.test.Item):
prefix = '.. >>> '
mod = py.std.types.ModuleType(self.fspath.purebasename)
for line in s.split('\n'):
line = line.strip()
if line.startswith(prefix):
exec py.code.Source(line[len(prefix):]).compile() in \
mod.__dict__

View File

@ -5,6 +5,21 @@ from py.__.test.outcome import Skipped, Failed, Passed
def setup_module(mod):
mod.tmpdir = py.test.ensuretemp('docdoctest')
def test_doctest_extra_exec():
# XXX get rid of the next line:
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
xtxt = tmpdir.join('y.txt')
xtxt.write(py.code.Source("""
hello::
.. >>> raise ValueError
>>> None
"""))
config = py.test.config._reparse([xtxt])
session = config.initsession()
session.main()
l = session.getitemoutcomepairs(Failed)
assert len(l) == 1
def test_doctest_basic():
# XXX get rid of the next line:
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))