From 12656124651cdd66343c5c2582bf910e5798cf07 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 28 Jul 2014 13:17:37 +0200 Subject: [PATCH] fix issue547 2.6 regression: capsys/capfd now work again when output capturing ("-s") is disabled. --- CHANGELOG | 2 ++ _pytest/capture.py | 4 +--- testing/test_capture.py | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b49cea8b8..a3af3378e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ NEXT ----------------------------------- +- fix issue547 capsys/capfd also work when output capturing ("-s") is disabled. + - address issue170: allow pytest.mark.xfail(...) to specify expected exceptions via an optional "raises=EXC" argument where EXC can be a single exception or a tuple of exception classes. Thanks David Mohr for the complete diff --git a/_pytest/capture.py b/_pytest/capture.py index 1eb20353d..f2445d7b5 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -20,7 +20,7 @@ patchsysdict = {0: 'stdin', 1: 'stdout', 2: 'stderr'} def pytest_addoption(parser): group = parser.getgroup("general") group._addoption( - '--capture', action="store", + '--capture', action="store", default="fd" if hasattr(os, "dup") else "sys", metavar="method", choices=['fd', 'sys', 'no'], help="per-test capturing method: one of fd|sys|no.") @@ -33,8 +33,6 @@ def pytest_addoption(parser): def pytest_load_initial_conftests(early_config, parser, args, __multicall__): ns = early_config.known_args_namespace pluginmanager = early_config.pluginmanager - if ns.capture == "no": - return capman = CaptureManager(ns.capture) pluginmanager.register(capman, "capturemanager") diff --git a/testing/test_capture.py b/testing/test_capture.py index 43b137d88..591b6761d 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -392,13 +392,14 @@ class TestLoggingInteraction: class TestCaptureFixture: - def test_std_functional(self, testdir): + @pytest.mark.parametrize("opt", [[], ["-s"]]) + def test_std_functional(self, testdir, opt): reprec = testdir.inline_runsource(""" def test_hello(capsys): print (42) out, err = capsys.readouterr() assert out.startswith("42") - """) + """, *opt) reprec.assertoutcome(passed=1) def test_capsyscapfd(self, testdir):