def test_capturing_hooks_simple(self): |
o = tmpdir.ensure('capturing', dir=1) |
tfile = o.join('test_capturing.py').write(py.code.Source(""" |
import py |
print "module level output" |
def test_capturing(): |
print 42 |
print >>py.std.sys.stderr, 23 |
def test_capturing_error(): |
print 1 |
print >>py.std.sys.stderr, 2 |
raise ValueError |
""")) |
conftest = o.join('conftest.py').write(py.code.Source(""" |
import py |
class Function(py.test.collect.Function): |
def startcapture(self): |
self._mycapture = None |
|
def finishcapture(self): |
self._testmycapture = None |
""")) |
-> session = self.mainsession(o) |
l = session.getitemoutcomepairs(Passed) |
assert len(l) == 1 |
item = l[0][0] |
assert hasattr(item, '_testmycapture') |
print item._testmycapture |
|
assert isinstance(item.parent, py.test.collect.Module) |
out, err = item.parent._getouterr() |
assert out.find('module level output') != -1 |
allout = self.file.getvalue() |
print "allout:", allout |
assert allout.find('module level output') != -1, ( |
"session didn't show module output") |