# HG changeset patch -- Bitbucket.org # Project pytest # URL http://bitbucket.org/hpk42/pytest/overview # User holger krekel <hol...@merlinux.eu> # Date 1291888831 -3600 # Node ID 7bca4ef2da85c138c72d21d279aa921b7d2cbcb0 # Parent 33139ed32f742292e68b2d69976164feb6703d0f check docstring at test time instead of runtime, improve and test warning on assertion turned off (thanks FND for reporting)
--- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -201,3 +201,14 @@ def test_traceback_failure(testdir): "*test_traceback_failure.py:4: AssertionError" ]) +...@pytest.mark.skipif("sys.version_info < (2,5)") +def test_warn_missing(testdir): + p1 = testdir.makepyfile("") + result = testdir.run(sys.executable, "-OO", "-m", "pytest", "-h") + result.stderr.fnmatch_lines([ + "*WARNING*assertion*", + ]) + result = testdir.run(sys.executable, "-OO", "-m", "pytest", "--no-assert") + result.stderr.fnmatch_lines([ + "*WARNING*assertion*", + ]) --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -218,6 +218,12 @@ class TestGeneralUsage: assert res.ret res.stderr.fnmatch_lines(["*ERROR*not found*"]) + def test_docstring_on_hookspec(self): + from _pytest import hookspec + for name, value in vars(hookspec).items(): + if name.startswith("pytest_"): + assert value.__doc__, "no docstring for %s" % name + class TestInvocationVariants: def test_earlyinit(self, testdir): p = testdir.makepyfile(""" --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 2.0.0 and 2.0.1.dev1 ---------------------------------------------- +- improve behaviour/warnings when running on top of "python -OO" + (assertions and docstrings are turned off, leading to potential + false positives) - introduce a pytest_cmdline_processargs(args) hook to allow dynamic computation of command line arguments. This fixes a regression because py.test prior to 2.0 --- a/_pytest/core.py +++ b/_pytest/core.py @@ -362,9 +362,6 @@ class HookRelay: added = False for name, method in vars(hookspecs).items(): if name.startswith(prefix): - if not method.__doc__: - raise ValueError("docstring required for hook %r, in %r" - % (method, hookspecs)) firstresult = getattr(method, 'firstresult', False) hc = HookCaller(self, name, firstresult=firstresult) setattr(self, name, hc) --- a/testing/test_core.py +++ b/testing/test_core.py @@ -319,25 +319,6 @@ class TestPytestPluginInteractions: res = config.hook.pytest_myhook(xyz=10) assert res == [11] - def test_addhooks_docstring_error(self, testdir): - newhooks = testdir.makepyfile(newhooks=""" - class A: # no pytest_ prefix - pass - def pytest_myhook(xyz): - pass - """) - conf = testdir.makeconftest(""" - import sys ; sys.path.insert(0, '.') - import newhooks - def pytest_addhooks(pluginmanager): - pluginmanager.addhooks(newhooks) - """) - res = testdir.runpytest() - assert res.ret != 0 - res.stderr.fnmatch_lines([ - "*docstring*pytest_myhook*newhooks*" - ]) - def test_addhooks_nohooks(self, testdir): conf = testdir.makeconftest(""" import sys --- a/_pytest/assertion.py +++ b/_pytest/assertion.py @@ -17,8 +17,8 @@ def pytest_configure(config): # turn call the hooks defined here as part of the # DebugInterpreter. config._monkeypatch = m = monkeypatch() + warn_about_missing_assertion() if not config.getvalue("noassert") and not config.getvalue("nomagic"): - warn_about_missing_assertion() def callbinrepr(op, left, right): hook_result = config.hook.pytest_assertrepr_compare( config=config, op=op, left=left, right=right) @@ -38,9 +38,8 @@ def warn_about_missing_assertion(): except AssertionError: pass else: - py.std.warnings.warn("Assertions are turned off!" - " (are you using python -O?)") - + sys.stderr.write("WARNING: failing tests may report as passing because " + "assertions are turned off! (are you using python -O?)\n") # Provide basestring in python3 try: _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn