Coverage for .tox/testcoverage/lib/python2.7/site-packages/_pytest/assertion/__init__ : 61%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" support for presenting detailed information in failing assertions. """
action="store", dest="assertmode", choices=("rewrite", "reinterp", "plain",), default="rewrite", metavar="MODE", help="""control assertion debugging tools. 'plain' performs no assertion debugging. 'reinterp' reinterprets assert statements after they failed to provide assertion expression information. 'rewrite' (the default) rewrites assert statements in test modules on import to provide assert expression information. """) action="store_true", default=False, dest="noassert", help="DEPRECATED equivalent to --assert=plain") action="store_true", default=False, help="DEPRECATED equivalent to --assert=plain")
"""State for the assertion plugin."""
mode = "plain" except ImportError: mode = "reinterp" else: # Both Jython and CPython 2.6.0 have AST bugs that make the # assertion rewriting hook malfunction. sys.version_info[:3] == (2, 6, 0)): mode = "reinterp" reinterpret.AssertionError) # noqa
# this hook is only called when test modules are collected # so for example not in the master process of pytest-xdist # (which does not collect test modules)
"""Check if we're currently running on a CI system.""" env_vars = ['CI', 'BUILD_NUMBER'] return any(var in os.environ for var in env_vars)
"""Setup the pytest_assertrepr_compare hook
The newinterpret and rewrite modules will use util._reprcompare if it exists to use custom reporting via the pytest_assertrepr_compare hook. This sets up this custom comparison for the test. """ """Call the pytest_assertrepr_compare hook and prepare the result
This uses the first result from the hook and then ensures the following: * Overly verbose explanations are dropped unless -vv was used or running on a CI. * Embedded newlines are escaped to help util.format_explanation() later. * If the rewrite mode is used embedded %-characters are replaced to protect later % formatting.
The result can be formatted by util.format_explanation() for pretty printing. """ hook_result = item.ihook.pytest_assertrepr_compare( config=item.config, op=op, left=left, right=right) for new_expl in hook_result: if new_expl: if (sum(len(p) for p in new_expl[1:]) > 80*8 and item.config.option.verbose < 2 and not _running_on_ci()): show_max = 10 truncated_lines = len(new_expl) - show_max new_expl[show_max:] = [py.builtin._totext( 'Detailed information truncated (%d more lines)' ', use "-vv" to show' % truncated_lines)] new_expl = [line.replace("\n", "\\n") for line in new_expl] res = py.builtin._totext("\n~").join(new_expl) if item.config.getvalue("assertmode") == "rewrite": res = res.replace("%", "%%") return res
"""Lazily import assertion related code.""" global rewrite, reinterpret
else: if mode == "rewrite": specifically = ("assertions which are not in test modules " "will be ignored") else: specifically = "failing tests may report as passing"
sys.stderr.write("WARNING: " + specifically + " because assert statements are not executed " "by the underlying Python interpreter " "(are you using python -O?)\n")
# Expose this plugin's implementation for the pytest_assertrepr_compare hook |