tentatively use internal list for cleanups at unconfigure time - this helps reporting with partially executed pytest_configure() hooks
This commit is contained in:
parent
06ca7090f9
commit
942ae47cd1
|
@ -1,2 +1,2 @@
|
|||
#
|
||||
__version__ = '2.0.3.dev3'
|
||||
__version__ = '2.0.3.dev4'
|
||||
|
|
|
@ -16,7 +16,8 @@ def pytest_configure(config):
|
|||
# py._code._assertionnew to detect this plugin was loaded and in
|
||||
# turn call the hooks defined here as part of the
|
||||
# DebugInterpreter.
|
||||
config._monkeypatch = m = monkeypatch()
|
||||
m = monkeypatch()
|
||||
config._cleanup.append(m.undo)
|
||||
warn_about_missing_assertion()
|
||||
if not config.getvalue("noassert") and not config.getvalue("nomagic"):
|
||||
def callbinrepr(op, left, right):
|
||||
|
@ -29,9 +30,6 @@ def pytest_configure(config):
|
|||
'AssertionError', py.code._AssertionError)
|
||||
m.setattr(py.code, '_reprcompare', callbinrepr)
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
config._monkeypatch.undo()
|
||||
|
||||
def warn_about_missing_assertion():
|
||||
try:
|
||||
assert False
|
||||
|
|
|
@ -12,6 +12,10 @@ def pytest_cmdline_parse(pluginmanager, args):
|
|||
config.trace.root.setwriter(sys.stderr.write)
|
||||
return config
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
for func in config._cleanup:
|
||||
func()
|
||||
|
||||
class Parser:
|
||||
""" Parser for command line arguments. """
|
||||
|
||||
|
@ -251,6 +255,7 @@ class Config(object):
|
|||
self._conftest = Conftest(onimport=self._onimportconftest)
|
||||
self.hook = self.pluginmanager.hook
|
||||
self._inicache = {}
|
||||
self._cleanup = []
|
||||
|
||||
@classmethod
|
||||
def fromdictargs(cls, option_dict, args):
|
||||
|
|
|
@ -48,15 +48,12 @@ class TempdirHandler:
|
|||
self.trace("finish")
|
||||
|
||||
def pytest_configure(config):
|
||||
config._mp = mp = monkeypatch()
|
||||
mp = monkeypatch()
|
||||
t = TempdirHandler(config)
|
||||
config._cleanup.extend([mp.undo, t.finish])
|
||||
mp.setattr(config, '_tmpdirhandler', t, raising=False)
|
||||
mp.setattr(pytest, 'ensuretemp', t.ensuretemp, raising=False)
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
config._tmpdirhandler.finish()
|
||||
config._mp.undo()
|
||||
|
||||
def pytest_funcarg__tmpdir(request):
|
||||
"""return a temporary directory path object
|
||||
which is unique to each test function invocation,
|
||||
|
|
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.3.dev3',
|
||||
version='2.0.3.dev4',
|
||||
url='http://pytest.org',
|
||||
license='MIT license',
|
||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||
|
|
|
@ -33,6 +33,19 @@ class TestGeneralUsage:
|
|||
'*INTERNALERROR*0 / 0*',
|
||||
])
|
||||
|
||||
def test_early_hook_configure_error_issue38(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
def pytest_configure():
|
||||
0 / 0
|
||||
""")
|
||||
result = testdir.runpytest(testdir.tmpdir)
|
||||
assert result.ret != 0
|
||||
# here we get it on stderr
|
||||
result.stderr.fnmatch_lines([
|
||||
'*INTERNALERROR*File*conftest.py*line 2*',
|
||||
'*0 / 0*',
|
||||
])
|
||||
|
||||
def test_file_not_found(self, testdir):
|
||||
result = testdir.runpytest("asd")
|
||||
assert result.ret != 0
|
||||
|
|
|
@ -44,7 +44,8 @@ class TestBinReprIntegration:
|
|||
config = testdir.parseconfig()
|
||||
plugin.pytest_configure(config)
|
||||
assert hook != py.code._reprcompare
|
||||
plugin.pytest_unconfigure(config)
|
||||
from _pytest.config import pytest_unconfigure
|
||||
pytest_unconfigure(config)
|
||||
assert hook == py.code._reprcompare
|
||||
|
||||
def callequal(left, right):
|
||||
|
|
Loading…
Reference in New Issue