refine and unify initial capturing - now works also if the logging module

is already used from an early-loaded conftest.py file (prior to option parsing)
This commit is contained in:
holger krekel
2011-01-18 12:51:21 +01:00
parent b8f0d10f80
commit d8d88ede65
6 changed files with 57 additions and 11 deletions
+9 -3
View File
@@ -19,10 +19,8 @@ def addouterr(rep, outerr):
if content:
repr.addsection("Captured std%s" % secname, content.rstrip())
def pytest_configure(config):
config.pluginmanager.register(CaptureManager(), 'capturemanager')
def pytest_unconfigure(config):
# registered in config.py during early conftest.py loading
capman = config.pluginmanager.getplugin('capturemanager')
while capman._method2capture:
name, cap = capman._method2capture.popitem()
@@ -67,6 +65,14 @@ class CaptureManager:
else:
raise ValueError("unknown capturing method: %r" % method)
def _getmethod_preoptionparse(self, args):
if '-s' in args or "--capture=no" in args:
return "no"
elif hasattr(os, 'dup') and '--capture=sys' not in args:
return "fd"
else:
return "sys"
def _getmethod(self, config, fspath):
if config.option.capture:
method = config.option.capture