fix issue8 : avoid errors caused by logging module wanting to close already closed streams.

The issue arose if logging was initialized while capturing was enabled
and then capturing streams were closed before process exit, leading
to the logging module to complain.
This commit is contained in:
holger krekel 2010-12-06 16:56:12 +01:00
parent c7531705fc
commit 2e80512bb8
5 changed files with 29 additions and 5 deletions

View File

@ -1,6 +1,7 @@
Changes between 2.0.0 and 2.0.1.dev1
----------------------------------------------
- fix issue8: no logging errors at process exit
- refinements to "collecting" output on non-ttys
- refine internal plugin registration and --traceconfig output
- introduce a mechanism to prevent/unregister plugins from the

View File

@ -26,7 +26,9 @@ def pytest_unconfigure(config):
capman = config.pluginmanager.getplugin('capturemanager')
while capman._method2capture:
name, cap = capman._method2capture.popitem()
cap.reset()
# XXX logging module may wants to close it itself on process exit
# otherwise we could do finalization here and call "reset()".
cap.suspend()
class NoCapture:
def startall(self):

View File

@ -151,15 +151,15 @@ class PluginManager(object):
except ImportError:
return # XXX issue a warning
for ep in iter_entry_points('pytest11'):
if ep.name in self._name2plugin:
name = ep.name
if name.startswith("pytest_"):
name = name[7:]
if ep.name in self._name2plugin or name in self._name2plugin:
continue
try:
plugin = ep.load()
except DistributionNotFound:
continue
name = ep.name
if name.startswith("pytest_"):
name = name[7:]
self.register(plugin, name=name)
def consider_preparse(self, args):

View File

@ -306,6 +306,26 @@ class TestLoggingInteraction:
# verify proper termination
assert "closed" not in s
def test_logging_initialized_in_test(self, testdir):
p = testdir.makepyfile("""
import sys
def test_something():
# pytest does not import logging
assert 'logging' not in sys.modules
import logging
logging.basicConfig()
logging.warn("hello432")
assert 0
""")
result = testdir.runpytest(p, "--traceconfig",
"-p", "no:capturelog")
assert result.ret != 0
result.stdout.fnmatch_lines([
"*hello432*",
])
assert 'operation on closed file' not in result.stderr.str()
class TestCaptureFuncarg:
def test_std_functional(self, testdir):
reprec = testdir.inline_runsource("""

View File

@ -73,3 +73,4 @@ rsyncdirs=tox.ini pytest.py _pytest testing
python_files=test_*.py *_test.py
python_classes=Test Acceptance
python_functions=test
pep8ignore = E401