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:
parent
c7531705fc
commit
2e80512bb8
|
@ -1,6 +1,7 @@
|
||||||
Changes between 2.0.0 and 2.0.1.dev1
|
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
|
- refinements to "collecting" output on non-ttys
|
||||||
- refine internal plugin registration and --traceconfig output
|
- refine internal plugin registration and --traceconfig output
|
||||||
- introduce a mechanism to prevent/unregister plugins from the
|
- introduce a mechanism to prevent/unregister plugins from the
|
||||||
|
|
|
@ -26,7 +26,9 @@ def pytest_unconfigure(config):
|
||||||
capman = config.pluginmanager.getplugin('capturemanager')
|
capman = config.pluginmanager.getplugin('capturemanager')
|
||||||
while capman._method2capture:
|
while capman._method2capture:
|
||||||
name, cap = capman._method2capture.popitem()
|
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:
|
class NoCapture:
|
||||||
def startall(self):
|
def startall(self):
|
||||||
|
|
|
@ -151,15 +151,15 @@ class PluginManager(object):
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return # XXX issue a warning
|
return # XXX issue a warning
|
||||||
for ep in iter_entry_points('pytest11'):
|
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
|
continue
|
||||||
try:
|
try:
|
||||||
plugin = ep.load()
|
plugin = ep.load()
|
||||||
except DistributionNotFound:
|
except DistributionNotFound:
|
||||||
continue
|
continue
|
||||||
name = ep.name
|
|
||||||
if name.startswith("pytest_"):
|
|
||||||
name = name[7:]
|
|
||||||
self.register(plugin, name=name)
|
self.register(plugin, name=name)
|
||||||
|
|
||||||
def consider_preparse(self, args):
|
def consider_preparse(self, args):
|
||||||
|
|
|
@ -306,6 +306,26 @@ class TestLoggingInteraction:
|
||||||
# verify proper termination
|
# verify proper termination
|
||||||
assert "closed" not in s
|
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:
|
class TestCaptureFuncarg:
|
||||||
def test_std_functional(self, testdir):
|
def test_std_functional(self, testdir):
|
||||||
reprec = testdir.inline_runsource("""
|
reprec = testdir.inline_runsource("""
|
||||||
|
|
Loading…
Reference in New Issue