a less ugly way to detect if assert rewriting is enabled
This commit is contained in:
parent
dd199d255c
commit
657522b629
|
@ -37,7 +37,6 @@ class AssertionState:
|
||||||
self.trace = config.trace.root.get("assertion")
|
self.trace = config.trace.root.get("assertion")
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
global rewrite_asserts
|
|
||||||
warn_about_missing_assertion()
|
warn_about_missing_assertion()
|
||||||
mode = config.getvalue("assertmode")
|
mode = config.getvalue("assertmode")
|
||||||
if config.getvalue("noassert") or config.getvalue("nomagic"):
|
if config.getvalue("noassert") or config.getvalue("nomagic"):
|
||||||
|
@ -58,8 +57,8 @@ def pytest_configure(config):
|
||||||
m.setattr(py.builtin.builtins, 'AssertionError',
|
m.setattr(py.builtin.builtins, 'AssertionError',
|
||||||
reinterpret.AssertionError)
|
reinterpret.AssertionError)
|
||||||
m.setattr(util, '_reprcompare', callbinrepr)
|
m.setattr(util, '_reprcompare', callbinrepr)
|
||||||
if mode != "on":
|
if mode == "on" and rewrite_asserts is None:
|
||||||
rewrite_asserts = None
|
mode = "old"
|
||||||
config._assertstate = AssertionState(config, mode)
|
config._assertstate = AssertionState(config, mode)
|
||||||
config._assertstate.trace("configured with mode set to %r" % (mode,))
|
config._assertstate.trace("configured with mode set to %r" % (mode,))
|
||||||
|
|
||||||
|
@ -81,7 +80,7 @@ def _write_pyc(co, source_path):
|
||||||
return pyc
|
return pyc
|
||||||
|
|
||||||
def pytest_pycollect_before_module_import(mod):
|
def pytest_pycollect_before_module_import(mod):
|
||||||
if rewrite_asserts is None:
|
if mod.config._assertstate.mode != "on":
|
||||||
return
|
return
|
||||||
# Some deep magic: load the source, rewrite the asserts, and write a
|
# Some deep magic: load the source, rewrite the asserts, and write a
|
||||||
# fake pyc, so that it'll be loaded when the module is imported.
|
# fake pyc, so that it'll be loaded when the module is imported.
|
||||||
|
@ -104,7 +103,7 @@ def pytest_pycollect_before_module_import(mod):
|
||||||
mod.config._assertstate.trace("wrote pyc: %r" % (mod._pyc,))
|
mod.config._assertstate.trace("wrote pyc: %r" % (mod._pyc,))
|
||||||
|
|
||||||
def pytest_pycollect_after_module_import(mod):
|
def pytest_pycollect_after_module_import(mod):
|
||||||
if rewrite_asserts is None or not hasattr(mod, "_pyc"):
|
if mod.config._assertstate.mode != "on" or not hasattr(mod, "_pyc"):
|
||||||
return
|
return
|
||||||
# Remove our tweaked pyc to avoid subtle bugs.
|
# Remove our tweaked pyc to avoid subtle bugs.
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue