[py-svn] commit/pytest: hpk42: rename and simplify the assert option:
Bitbucket
commits-noreply at bitbucket.org
Tue Jul 5 17:34:49 CEST 2011
1 new changeset in pytest:
http://bitbucket.org/hpk42/pytest/changeset/51185a70d005/
changeset: 51185a70d005
user: hpk42
date: 2011-07-05 17:29:53
summary: rename and simplify the assert option:
cmdline usage is now: --assert=rewrite/reinterp/plain
there is no conflict detection (don't think that's neccessary)
affected #: 5 files (345 bytes)
--- a/_pytest/__init__.py Tue Jul 05 15:21:08 2011 +0200
+++ b/_pytest/__init__.py Tue Jul 05 17:29:53 2011 +0200
@@ -1,2 +1,2 @@
#
-__version__ = '2.1.0.dev5'
+__version__ = '2.1.0.dev6'
--- a/_pytest/assertion/__init__.py Tue Jul 05 15:21:08 2011 +0200
+++ b/_pytest/assertion/__init__.py Tue Jul 05 17:29:53 2011 +0200
@@ -9,18 +9,18 @@
def pytest_addoption(parser):
group = parser.getgroup("debugconfig")
- group.addoption('--assertmode', action="store", dest="assertmode",
- choices=("rewrite", "reinterp", "off", "default"),
- default="default", metavar="off|reinterp|rewrite",
+ group.addoption('--assert', action="store", dest="assertmode",
+ choices=("rewrite", "reinterp", "plain",),
+ default="rewrite", metavar="MODE",
help="""control assertion debugging tools.
-'off' performs no assertion debugging.
-'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.""")
+'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. """)
group.addoption('--no-assert', action="store_true", default=False,
- dest="noassert", help="DEPRECATED equivalent to --assertmode=off")
+ dest="noassert", help="DEPRECATED equivalent to --assert=plain")
group.addoption('--nomagic', action="store_true", default=False,
- dest="nomagic", help="DEPRECATED equivalent to --assertmode=off")
+ dest="nomagic", help="DEPRECATED equivalent to --assert=plain")
class AssertionState:
"""State for the assertion plugin."""
@@ -33,17 +33,13 @@
def pytest_configure(config):
mode = config.getvalue("assertmode")
if config.getvalue("noassert") or config.getvalue("nomagic"):
- if mode not in ("off", "default"):
- raise pytest.UsageError("assertion options conflict")
- mode = "off"
- elif mode == "default":
- mode = "rewrite"
+ mode = "plain"
if mode == "rewrite":
try:
import ast
except ImportError:
mode = "reinterp"
- if mode != "off":
+ if mode != "plain":
_load_modules(mode)
def callbinrepr(op, left, right):
hook_result = config.hook.pytest_assertrepr_compare(
@@ -104,7 +100,8 @@
specifically = "failing tests may report as passing"
sys.stderr.write("WARNING: " + specifically +
- " because assertions are turned off "
+ " because assert statements are not executed "
+ "by the underlying Python interpreter "
"(are you using python -O?)\n")
pytest_assertrepr_compare = util.assertrepr_compare
--- a/doc/assert.txt Tue Jul 05 15:21:08 2011 +0200
+++ b/doc/assert.txt Tue Jul 05 17:29:53 2011 +0200
@@ -23,7 +23,7 @@
$ py.test test_assert1.py
============================= test session starts ==============================
- platform darwin -- Python 2.7.0 -- pytest-2.1.0.dev4
+ platform linux2 -- Python 2.6.6 -- pytest-2.1.0.dev6
collecting ... collected 1 items
test_assert1.py F
@@ -37,7 +37,7 @@
E + where 3 = f()
test_assert1.py:5: AssertionError
- =========================== 1 failed in 0.05 seconds ===========================
+ =========================== 1 failed in 0.01 seconds ===========================
py.test has support for showing the values of the most common subexpressions
including calls, attributes, comparisons, and binary and unary
@@ -105,7 +105,7 @@
$ py.test test_assert2.py
============================= test session starts ==============================
- platform darwin -- Python 2.7.0 -- pytest-2.1.0.dev4
+ platform linux2 -- Python 2.6.6 -- pytest-2.1.0.dev6
collecting ... collected 1 items
test_assert2.py F
@@ -124,7 +124,7 @@
E '5'
test_assert2.py:5: AssertionError
- =========================== 1 failed in 0.05 seconds ===========================
+ =========================== 1 failed in 0.01 seconds ===========================
Special comparisons are done for a number of cases:
@@ -181,7 +181,7 @@
E vals: 1 != 2
test_foocompare.py:8: AssertionError
- 1 failed in 0.05 seconds
+ 1 failed in 0.01 seconds
.. _assert-details:
.. _`assert introspection`:
@@ -212,8 +212,8 @@
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
+ this is the case, simply use ``--assert=reinterp`` or
+ ``--assert=plain``. 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
@@ -221,7 +221,7 @@
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=reinterp`` option.
+``--assert=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
@@ -238,11 +238,11 @@
content = f.read()
assert content != '...'
-All assert introspection can be turned off by passing ``--assertmode=off``.
+All assert introspection can be turned off by passing ``--assert=plain``.
.. versionadded:: 2.1
Add assert rewriting as an alternate introspection technique.
.. versionchanged:: 2.1
- Introduce the ``--assertmode`` option. Deprecate ``--no-assert`` and
+ Introduce the ``--assert`` option. Deprecate ``--no-assert`` and
``--nomagic``.
--- a/setup.py Tue Jul 05 15:21:08 2011 +0200
+++ b/setup.py Tue Jul 05 17:29:53 2011 +0200
@@ -22,7 +22,7 @@
name='pytest',
description='py.test: simple powerful testing with Python',
long_description = long_description,
- version='2.1.0.dev5',
+ version='2.1.0.dev6',
url='http://pytest.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
--- a/testing/test_assertion.py Tue Jul 05 15:21:08 2011 +0200
+++ b/testing/test_assertion.py Tue Jul 05 17:29:53 2011 +0200
@@ -179,26 +179,20 @@
off_options = (("--no-assert",),
("--nomagic",),
("--no-assert", "--nomagic"),
- ("--assertmode=off",),
- ("--assertmode=off", "--no-assert"),
- ("--assertmode=off", "--nomagic"),
- ("--assertmode=off," "--no-assert", "--nomagic"))
+ ("--assert=plain",),
+ ("--assert=plain", "--no-assert"),
+ ("--assert=plain", "--nomagic"),
+ ("--assert=plain", "--no-assert", "--nomagic"))
for opt in off_options:
result = testdir.runpytest(*opt)
assert "3 == 4" not in result.stdout.str()
- for mode in "rewrite", "reinterp":
- for other_opt in off_options[:3]:
- opt = ("--assertmode=" + mode,) + other_opt
- result = testdir.runpytest(*opt)
- assert result.ret == 3
- assert "assertion options conflict" in result.stderr.str()
def test_old_assert_mode(testdir):
testdir.makepyfile("""
def test_in_old_mode():
assert "@py_builtins" not in globals()
""")
- result = testdir.runpytest("--assertmode=reinterp")
+ result = testdir.runpytest("--assert=reinterp")
assert result.ret == 0
def test_triple_quoted_string_issue113(testdir):
@@ -246,11 +240,11 @@
p1 = testdir.makepyfile("")
result = testdir.run(sys.executable, "-OO", "-m", "pytest", "-h")
result.stderr.fnmatch_lines([
- "*WARNING*assertion*",
+ "*WARNING*assert statements are not executed*",
])
result = testdir.run(sys.executable, "-OO", "-m", "pytest", "--no-assert")
result.stderr.fnmatch_lines([
- "*WARNING*assertion*",
+ "*WARNING*assert statements are not executed*",
])
def test_load_fake_pyc(testdir):
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.
More information about the pytest-commit
mailing list