Fix capturing with --setup-only/--setup-plan
This commit is contained in:
parent
ecc97aa3b9
commit
1a5e530b98
|
@ -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 >" %
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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'
|
||||
])
|
||||
|
|
Loading…
Reference in New Issue