diff --git a/_pytest/python.py b/_pytest/python.py index a17cc29dc..c5418b4d7 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -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 ("" % diff --git a/_pytest/runner.py b/_pytest/runner.py index efcb28108..dff321a75 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -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))) diff --git a/testing/python/setup_only.py b/testing/python/setup_only.py index 11329775c..eef2857bb 100644 --- a/testing/python/setup_only.py +++ b/testing/python/setup_only.py @@ -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' + ])