fix issue93 - hide output of code in early-loaded conftest files
--HG-- branch : trunk
This commit is contained in:
parent
f466d35771
commit
b4210f3ae0
|
@ -5,7 +5,7 @@ see http://pytest.org for documentation and details
|
|||
|
||||
(c) Holger Krekel and others, 2004-2010
|
||||
"""
|
||||
__version__ = "2.0.0.dev4"
|
||||
__version__ = '2.0.0.dev6'
|
||||
|
||||
__all__ = ['config', 'cmdline']
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import py
|
|||
import sys, os
|
||||
from pytest._core import PluginManager
|
||||
|
||||
|
||||
def pytest_cmdline_parse(pluginmanager, args):
|
||||
config = Config(pluginmanager)
|
||||
config.parse(args)
|
||||
|
@ -283,11 +284,25 @@ class Config(object):
|
|||
if not hasattr(self.option, opt.dest):
|
||||
setattr(self.option, opt.dest, opt.default)
|
||||
|
||||
def _setinitialconftest(self, args):
|
||||
# capture output during conftest init (#issue93)
|
||||
name = hasattr(os, 'dup') and 'StdCaptureFD' or 'StdCapture'
|
||||
cap = getattr(py.io, name)()
|
||||
try:
|
||||
try:
|
||||
self._conftest.setinitial(args)
|
||||
finally:
|
||||
out, err = cap.reset()
|
||||
except:
|
||||
sys.stdout.write(out)
|
||||
sys.stderr.write(err)
|
||||
raise
|
||||
|
||||
def _preparse(self, args):
|
||||
self.pluginmanager.consider_setuptools_entrypoints()
|
||||
self.pluginmanager.consider_env()
|
||||
self.pluginmanager.consider_preparse(args)
|
||||
self._conftest.setinitial(args)
|
||||
self._setinitialconftest(args)
|
||||
self.pluginmanager.do_addoption(self._parser)
|
||||
|
||||
def parse(self, args):
|
||||
|
|
2
setup.py
2
setup.py
|
@ -22,7 +22,7 @@ def main():
|
|||
name='pytest',
|
||||
description='py.test: simple powerful testing with Python',
|
||||
long_description = long_description,
|
||||
version='2.0.0.dev5',
|
||||
version='2.0.0.dev6',
|
||||
url='http://pytest.org',
|
||||
license='MIT license',
|
||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||
|
|
|
@ -138,15 +138,23 @@ class TestGeneralUsage:
|
|||
"*Module*test_issue88*",
|
||||
])
|
||||
|
||||
@py.test.mark.xfail
|
||||
def test_issue93_initialnode_importing_capturing(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
print "should not be seen"
|
||||
print ("should not be seen")
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
assert result.ret == 0
|
||||
assert "should not be seen" not in result.stdout.str()
|
||||
|
||||
def test_conftest_printing_shows_if_error(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
print ("should be seen")
|
||||
assert 0
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
assert result.ret != 0
|
||||
assert "should be seen" in result.stdout.str()
|
||||
|
||||
@py.test.mark.skipif("not hasattr(os, 'symlink')")
|
||||
def test_chdir(self, testdir):
|
||||
testdir.tmpdir.join("py").mksymlinkto(py._pydir)
|
||||
|
|
Loading…
Reference in New Issue