fix issue124 - make test reporting more resilient against tests changing FD 1
--HG-- branch : trunk
This commit is contained in:
parent
cebcdb83cf
commit
7c6e47f715
|
@ -2,6 +2,8 @@
|
||||||
Changes between 1.3.4 and 1.4.0.dev0
|
Changes between 1.3.4 and 1.4.0.dev0
|
||||||
==================================================
|
==================================================
|
||||||
|
|
||||||
|
- fix issue124 - make reporting more resilient against tests opening
|
||||||
|
files on filedescriptor 1 (stdout).
|
||||||
- fix issue109 - sibling conftest.py files will not be loaded.
|
- fix issue109 - sibling conftest.py files will not be loaded.
|
||||||
(and Directory collectors cannot be customized anymore from a Directory's
|
(and Directory collectors cannot be customized anymore from a Directory's
|
||||||
conftest.py - this needs to happen at least one level up).
|
conftest.py - this needs to happen at least one level up).
|
||||||
|
|
|
@ -5,6 +5,7 @@ This is a good source for looking at the various reporting hooks.
|
||||||
"""
|
"""
|
||||||
import py
|
import py
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
group = parser.getgroup("terminal reporting", "reporting", after="general")
|
group = parser.getgroup("terminal reporting", "reporting", after="general")
|
||||||
|
@ -29,8 +30,6 @@ def pytest_addoption(parser):
|
||||||
help="don't cut any tracebacks (default is to cut).")
|
help="don't cut any tracebacks (default is to cut).")
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
if config.option.showfuncargs:
|
|
||||||
return
|
|
||||||
if config.option.collectonly:
|
if config.option.collectonly:
|
||||||
reporter = CollectonlyReporter(config)
|
reporter = CollectonlyReporter(config)
|
||||||
else:
|
else:
|
||||||
|
@ -75,6 +74,15 @@ class TerminalReporter:
|
||||||
self.curdir = py.path.local()
|
self.curdir = py.path.local()
|
||||||
if file is None:
|
if file is None:
|
||||||
file = py.std.sys.stdout
|
file = py.std.sys.stdout
|
||||||
|
# we try hard to make printing resilient against
|
||||||
|
# later changes on FD level.
|
||||||
|
if hasattr(os, 'dup') and hasattr(file, 'fileno'):
|
||||||
|
try:
|
||||||
|
newfd = os.dup(file.fileno())
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
file = os.fdopen(newfd, file.mode, 1)
|
||||||
self._tw = py.io.TerminalWriter(file)
|
self._tw = py.io.TerminalWriter(file)
|
||||||
self.currentfspath = None
|
self.currentfspath = None
|
||||||
self.reportchars = getreportopt(config)
|
self.reportchars = getreportopt(config)
|
||||||
|
|
|
@ -377,4 +377,3 @@ def test_fdfuncarg_skips_on_no_osdup(testdir):
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
"*1 skipped*"
|
"*1 skipped*"
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -609,3 +609,21 @@ def pytest_report_header(config):
|
||||||
"line2",
|
"line2",
|
||||||
"*hello: info*",
|
"*hello: info*",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
needsosdup = py.test.mark.xfail("not hasattr(os, 'dup')")
|
||||||
|
def test_fdopen_kept_alive_issue124(testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import os, sys
|
||||||
|
k = []
|
||||||
|
def test_open_file_and_keep_alive(capfd):
|
||||||
|
stdout = os.fdopen(1, 'w', 1)
|
||||||
|
k.append(stdout)
|
||||||
|
|
||||||
|
def test_close_kept_alive_file():
|
||||||
|
stdout = k.pop()
|
||||||
|
stdout.close()
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest("-s")
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*2 passed*"
|
||||||
|
])
|
||||||
|
|
Loading…
Reference in New Issue