2 new changesets in pytest: http://bitbucket.org/hpk42/pytest/changeset/abc3befb8883/ changeset: abc3befb8883 user: gutworth date: 2011-06-29 16:44:04 summary: rename --assertmode choices to be more explicit affected #: 2 files (90 bytes)
--- a/_pytest/assertion/__init__.py Tue Jun 28 21:13:12 2011 -0500 +++ b/_pytest/assertion/__init__.py Wed Jun 29 09:44:04 2011 -0500 @@ -12,13 +12,13 @@ def pytest_addoption(parser): group = parser.getgroup("debugconfig") group.addoption('--assertmode', action="store", dest="assertmode", - choices=("on", "old", "off", "default"), default="default", - metavar="on|old|off", + choices=("rewrite", "reinterp", "off", "default"), + default="default", metavar="off|reinterp|rewrite", help="""control assertion debugging tools. 'off' performs no assertion debugging. -'old' reinterprets the expressions in asserts to glean information. -'on' (the default) rewrites the assert statements in test modules to provide -sub-expression results.""") +'reinterp' reinterprets the expressions in asserts to glean information. +'rewrite' (the default) rewrites the assert statements in test modules on import +to provide sub-expression results.""") group.addoption('--no-assert', action="store_true", default=False, dest="noassert", help="DEPRECATED equivalent to --assertmode=off") group.addoption('--nomagic', action="store_true", default=False, @@ -39,9 +39,9 @@ raise pytest.UsageError("assertion options conflict") mode = "off" elif mode == "default": - mode = "on" + mode = "rewrite" if mode == "on" and not REWRITING_AVAILABLE: - mode = "old" + mode = "reinterp" if mode != "off": _load_modules(mode) def callbinrepr(op, left, right): @@ -56,7 +56,7 @@ reinterpret.AssertionError) m.setattr(util, '_reprcompare', callbinrepr) hook = None - if mode == "on": + if mode == "rewrite": hook = rewrite.AssertionRewritingHook() sys.meta_path.append(hook) warn_about_missing_assertion(mode) @@ -65,7 +65,7 @@ config._assertstate.trace("configured with mode set to %r" % (mode,)) def pytest_unconfigure(config): - if config._assertstate.mode == "on": + if config._assertstate.mode == "rewrite": rewrite._drain_pycs(config._assertstate) hook = config._assertstate.hook if hook is not None: @@ -77,7 +77,7 @@ hook.set_session(session) def pytest_sessionfinish(session): - if session.config._assertstate.mode == "on": + if session.config._assertstate.mode == "rewrite": rewrite._drain_pycs(session.config._assertstate) hook = session.config._assertstate.hook if hook is not None: @@ -87,7 +87,7 @@ """Lazily import assertion related code.""" global rewrite, reinterpret from _pytest.assertion import reinterpret - if mode == "on": + if mode == "rewrite": from _pytest.assertion import rewrite def warn_about_missing_assertion(mode): @@ -96,7 +96,7 @@ except AssertionError: pass else: - if mode == "on": + if mode == "rewrite": specifically = ("assertions which are not in test modules " "will be ignored") else: --- a/testing/test_assertion.py Tue Jun 28 21:13:12 2011 -0500 +++ b/testing/test_assertion.py Wed Jun 29 09:44:04 2011 -0500 @@ -182,7 +182,7 @@ for opt in off_options: result = testdir.runpytest(*opt) 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]: opt = ("--assertmode=" + mode,) + other_opt result = testdir.runpytest(*opt) @@ -194,7 +194,7 @@ def test_in_old_mode(): assert "@py_builtins" not in globals() """) - result = testdir.runpytest("--assertmode=old") + result = testdir.runpytest("--assertmode=reinterp") assert result.ret == 0 def test_triple_quoted_string_issue113(testdir): http://bitbucket.org/hpk42/pytest/changeset/5a104e61c354/ changeset: 5a104e61c354 user: gutworth date: 2011-06-29 17:52:39 summary: update assert docs affected #: 1 file (48 bytes) --- a/doc/assert.txt Wed Jun 29 09:44:04 2011 -0500 +++ b/doc/assert.txt Wed Jun 29 10:52:39 2011 -0500 @@ -196,30 +196,32 @@ assert statements before they are run or re-evaluating the assert expression and recording the intermediate values. Which technique is used depends on the location of the assert, py.test's configuration, and Python version being used -to run py.test. However, for assert statements with a manually provided -message, i.e. ``assert expr, message``, no assertion introspection takes place and the manually provided message will be rendered in tracebacks. +to run py.test. Note that for assert statements with a manually provided +message, i.e. ``assert expr, message``, no assertion introspection takes place +and the manually provided message will be rendered in tracebacks. By default, if the Python version is greater than or equal to 2.6, py.test rewrites assert statements in test modules. Rewritten assert statements put introspection information into the assertion failure message. py.test only rewrites test modules directly discovered by its test collection process, so -asserts in supporting modules will not be rewritten. +asserts in supporting modules which are not themselves test modules will not be +rewritten. .. note:: - py.test rewrites test modules as it collects tests from them. It does this by - writing a new pyc file which Python loads when the test module is - imported. If the module has already been loaded (it is in sys.modules), - though, Python will not load the rewritten module. This means if a test - module imports another test module which has not already been rewritten, then - py.test will not be able to rewrite the second module. + py.test rewrites test modules on import. It does this by using an import hook + to write a new pyc files. Most of the time this works transparently. However, + if you are messing with import yourself, the import hook may interfere. If + this is the case, simply use ``--assertmode=reinterp`` or + ``--assertmode=off``. Additionally, rewriting will fail silently if it cannot + write new pycs, i.e. in a read-only filesystem or a zipfile. If an assert statement has not been rewritten or the Python version is less than 2.6, py.test falls back on assert reinterpretation. In assert reinterpretation, py.test walks the frame of the function containing the assert statement to discover sub-expression results of the failing assert statement. You can force py.test to always use assertion reinterpretation by passing the -``--assertmode=old`` option. +``--assertmode=reinterp`` option. Assert reinterpretation has a caveat not present with assert rewriting: If evaluating the assert expression has side effects you may get a warning that the @@ -244,5 +246,3 @@ .. versionchanged:: 2.1 Introduce the ``--assertmode`` option. Deprecate ``--no-assert`` and ``--nomagic``. - - Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn