rename --assertmode choices to be more explicit
This commit is contained in:
parent
48b76c7544
commit
aa7f7a1c71
|
@ -12,13 +12,13 @@ REWRITING_AVAILABLE = "_ast" in sys.builtin_module_names
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
group = parser.getgroup("debugconfig")
|
group = parser.getgroup("debugconfig")
|
||||||
group.addoption('--assertmode', action="store", dest="assertmode",
|
group.addoption('--assertmode', action="store", dest="assertmode",
|
||||||
choices=("on", "old", "off", "default"), default="default",
|
choices=("rewrite", "reinterp", "off", "default"),
|
||||||
metavar="on|old|off",
|
default="default", metavar="off|reinterp|rewrite",
|
||||||
help="""control assertion debugging tools.
|
help="""control assertion debugging tools.
|
||||||
'off' performs no assertion debugging.
|
'off' performs no assertion debugging.
|
||||||
'old' reinterprets the expressions in asserts to glean information.
|
'reinterp' reinterprets the expressions in asserts to glean information.
|
||||||
'on' (the default) rewrites the assert statements in test modules to provide
|
'rewrite' (the default) rewrites the assert statements in test modules on import
|
||||||
sub-expression results.""")
|
to provide sub-expression results.""")
|
||||||
group.addoption('--no-assert', action="store_true", default=False,
|
group.addoption('--no-assert', action="store_true", default=False,
|
||||||
dest="noassert", help="DEPRECATED equivalent to --assertmode=off")
|
dest="noassert", help="DEPRECATED equivalent to --assertmode=off")
|
||||||
group.addoption('--nomagic', action="store_true", default=False,
|
group.addoption('--nomagic', action="store_true", default=False,
|
||||||
|
@ -39,9 +39,9 @@ def pytest_configure(config):
|
||||||
raise pytest.UsageError("assertion options conflict")
|
raise pytest.UsageError("assertion options conflict")
|
||||||
mode = "off"
|
mode = "off"
|
||||||
elif mode == "default":
|
elif mode == "default":
|
||||||
mode = "on"
|
mode = "rewrite"
|
||||||
if mode == "on" and not REWRITING_AVAILABLE:
|
if mode == "on" and not REWRITING_AVAILABLE:
|
||||||
mode = "old"
|
mode = "reinterp"
|
||||||
if mode != "off":
|
if mode != "off":
|
||||||
_load_modules(mode)
|
_load_modules(mode)
|
||||||
def callbinrepr(op, left, right):
|
def callbinrepr(op, left, right):
|
||||||
|
@ -56,7 +56,7 @@ def pytest_configure(config):
|
||||||
reinterpret.AssertionError)
|
reinterpret.AssertionError)
|
||||||
m.setattr(util, '_reprcompare', callbinrepr)
|
m.setattr(util, '_reprcompare', callbinrepr)
|
||||||
hook = None
|
hook = None
|
||||||
if mode == "on":
|
if mode == "rewrite":
|
||||||
hook = rewrite.AssertionRewritingHook()
|
hook = rewrite.AssertionRewritingHook()
|
||||||
sys.meta_path.append(hook)
|
sys.meta_path.append(hook)
|
||||||
warn_about_missing_assertion(mode)
|
warn_about_missing_assertion(mode)
|
||||||
|
@ -65,7 +65,7 @@ def pytest_configure(config):
|
||||||
config._assertstate.trace("configured with mode set to %r" % (mode,))
|
config._assertstate.trace("configured with mode set to %r" % (mode,))
|
||||||
|
|
||||||
def pytest_unconfigure(config):
|
def pytest_unconfigure(config):
|
||||||
if config._assertstate.mode == "on":
|
if config._assertstate.mode == "rewrite":
|
||||||
rewrite._drain_pycs(config._assertstate)
|
rewrite._drain_pycs(config._assertstate)
|
||||||
hook = config._assertstate.hook
|
hook = config._assertstate.hook
|
||||||
if hook is not None:
|
if hook is not None:
|
||||||
|
@ -77,7 +77,7 @@ def pytest_sessionstart(session):
|
||||||
hook.set_session(session)
|
hook.set_session(session)
|
||||||
|
|
||||||
def pytest_sessionfinish(session):
|
def pytest_sessionfinish(session):
|
||||||
if session.config._assertstate.mode == "on":
|
if session.config._assertstate.mode == "rewrite":
|
||||||
rewrite._drain_pycs(session.config._assertstate)
|
rewrite._drain_pycs(session.config._assertstate)
|
||||||
hook = session.config._assertstate.hook
|
hook = session.config._assertstate.hook
|
||||||
if hook is not None:
|
if hook is not None:
|
||||||
|
@ -87,7 +87,7 @@ def _load_modules(mode):
|
||||||
"""Lazily import assertion related code."""
|
"""Lazily import assertion related code."""
|
||||||
global rewrite, reinterpret
|
global rewrite, reinterpret
|
||||||
from _pytest.assertion import reinterpret
|
from _pytest.assertion import reinterpret
|
||||||
if mode == "on":
|
if mode == "rewrite":
|
||||||
from _pytest.assertion import rewrite
|
from _pytest.assertion import rewrite
|
||||||
|
|
||||||
def warn_about_missing_assertion(mode):
|
def warn_about_missing_assertion(mode):
|
||||||
|
@ -96,7 +96,7 @@ def warn_about_missing_assertion(mode):
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if mode == "on":
|
if mode == "rewrite":
|
||||||
specifically = ("assertions which are not in test modules "
|
specifically = ("assertions which are not in test modules "
|
||||||
"will be ignored")
|
"will be ignored")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -182,7 +182,7 @@ def test_assertion_options(testdir):
|
||||||
for opt in off_options:
|
for opt in off_options:
|
||||||
result = testdir.runpytest(*opt)
|
result = testdir.runpytest(*opt)
|
||||||
assert "3 == 4" not in result.stdout.str()
|
assert "3 == 4" not in result.stdout.str()
|
||||||
for mode in "on", "old":
|
for mode in "rewrite", "reinterp":
|
||||||
for other_opt in off_options[:3]:
|
for other_opt in off_options[:3]:
|
||||||
opt = ("--assertmode=" + mode,) + other_opt
|
opt = ("--assertmode=" + mode,) + other_opt
|
||||||
result = testdir.runpytest(*opt)
|
result = testdir.runpytest(*opt)
|
||||||
|
@ -194,7 +194,7 @@ def test_old_assert_mode(testdir):
|
||||||
def test_in_old_mode():
|
def test_in_old_mode():
|
||||||
assert "@py_builtins" not in globals()
|
assert "@py_builtins" not in globals()
|
||||||
""")
|
""")
|
||||||
result = testdir.runpytest("--assertmode=old")
|
result = testdir.runpytest("--assertmode=reinterp")
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
|
|
||||||
def test_triple_quoted_string_issue113(testdir):
|
def test_triple_quoted_string_issue113(testdir):
|
||||||
|
|
Loading…
Reference in New Issue