always dupfile if os.dup is available

This commit is contained in:
holger krekel 2013-10-03 16:47:55 +02:00
parent 2248a31a44
commit ae090740c5
2 changed files with 12 additions and 9 deletions

View File

@ -37,7 +37,7 @@ def pytest_configure(config):
# we try hard to make printing resilient against
# later changes on FD level. (unless capturing is off/sys)
stdout = sys.stdout
if config.option.capture == "fd" and hasattr(os, "dup"):
if hasattr(os, "dup"):
try:
newstdout = py.io.dupfile(stdout, buffering=1,
encoding=stdout.encoding)

View File

@ -677,14 +677,6 @@ def test_fdopen_kept_alive_issue124(testdir):
"*2 passed*"
])
def test_nofd_manipulation_with_capture_disabled(testdir):
from _pytest.terminal import pytest_configure
config = testdir.parseconfig("--capture=no")
stdout = sys.stdout
pytest_configure(config)
reporter = config.pluginmanager.getplugin('terminalreporter')
assert reporter._tw._file == stdout
def test_tbstyle_native_setup_error(testdir):
p = testdir.makepyfile("""
import pytest
@ -712,3 +704,14 @@ def test_terminal_summary(testdir):
*==== hello ====*
world
""")
@pytest.mark.xfail("not hasattr(os, 'dup')")
def test_fd_fixing(testdir):
testdir.makepyfile("""
import os
os.close(1)
def test_fdclose():
os.close(2)
""")
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines("*1 pass*")