Fix capturing with --setup-only/--setup-plan

This commit is contained in:
Vasily Kuznetsov 2016-06-23 10:23:04 +02:00
parent ecc97aa3b9
commit 1a5e530b98
3 changed files with 25 additions and 2 deletions

View File

@ -2552,7 +2552,7 @@ class FixtureDef:
config = self._fixturemanager.config
capman = config.pluginmanager.getplugin('capturemanager')
if capman:
capman.suspendcapture()
out, err = capman.suspendcapture()
tw = config.get_terminal_writer()
tw.line()
@ -2572,6 +2572,8 @@ class FixtureDef:
if capman:
capman.resumecapture()
sys.stdout.write(out)
sys.stderr.write(err)
def __repr__(self):
return ("<FixtureDef name=%r scope=%r baseid=%r >" %

View File

@ -91,7 +91,7 @@ def show_test_item(item):
tw = item.config.get_terminal_writer()
tw.line()
tw.write(' ' * 8)
tw.write('{0}'.format(item._nodeid))
tw.write(item._nodeid)
used_fixtures = sorted(item._fixtureinfo.name2fixturedefs.keys())
if used_fixtures:
tw.write(' (fixtures used: {0})'.format(', '.join(used_fixtures)))

View File

@ -179,3 +179,24 @@ def test_dynamic_fixture_request(testdir):
'*SETUP F dynamically_requested_fixture',
'*TEARDOWN F dynamically_requested_fixture'
])
def test_capturing(testdir):
p = testdir.makepyfile('''
import pytest, sys
@pytest.fixture()
def one():
sys.stdout.write('this should be captured')
sys.stderr.write('this should also be captured')
@pytest.fixture()
def two(one):
assert 0
def test_capturing(two):
pass
''')
result = testdir.runpytest('--setup-only', p)
result.stdout.fnmatch_lines([
'this should be captured',
'this should also be captured'
])