diff options
author | James J Lee <jjl@pobox.com> | 2008-03-11 00:01:58 +0000 |
---|---|---|
committer | James J Lee <jjl@pobox.com> | 2008-03-11 00:01:58 +0000 |
commit | 5e21af79735f7dce42a229135ac502be43b1dcf6 (patch) | |
tree | c1a59910b722831248b303755410468b3af130de | |
parent | ba5c083f173b526306bee27774ef9917dbed9c01 (diff) | |
download | nose-5e21af79735f7dce42a229135ac502be43b1dcf6.tar.gz |
Add the tests for #142 I intended to commit with r439
4 files changed, 170 insertions, 0 deletions
diff --git a/functional_tests/doc_tests/test_issue142/errorclass_failure.rst b/functional_tests/doc_tests/test_issue142/errorclass_failure.rst new file mode 100644 index 0000000..f6100e4 --- /dev/null +++ b/functional_tests/doc_tests/test_issue142/errorclass_failure.rst @@ -0,0 +1,127 @@ +Failure of Errorclasses +----------------------- + +Errorclasses (skips, deprecations, etc.) define whether or not they +represent test failures. + + >>> import os + >>> import sys + + >>> from nose.plugins.plugintest import run + >>> from nose.plugins.skip import Skip + >>> from nose.plugins.deprecated import Deprecated + + >>> support = os.path.join(os.path.dirname(__file__), 'support') + >>> sys.path.insert(0, support) + + >>> from errorclass_failure_plugin import (Todo, TodoPlugin, + ... NonFailureTodoPlugin) + + >>> todo_test = os.path.join(support, 'errorclass_failing_test.py') + >>> misc_test = os.path.join(support, 'errorclass_tests.py') + +nose.plugins.errorclass.ErrorClass has an argument isfailure . With a +true isfailure, when the errorclass' exception is caught by nose, +tracebacks are printed. + + >>> run(argv=["nosetests", "-v", "--with-todo", todo_test], + ... plugins=[TodoPlugin()]) # doctest: +REPORT_NDIFF + errorclass_failing_test.test_todo ... TODO: fix me + errorclass_failing_test.test_2 ... ok + <BLANKLINE> + ====================================================================== + TODO: errorclass_failing_test.test_todo + ---------------------------------------------------------------------- + Traceback (most recent call last): + ... + Todo: fix me + <BLANKLINE> + ---------------------------------------------------------------------- + Ran 2 tests in ...s + <BLANKLINE> + FAILED (TODO=1) + + +Also, --stop stops the test run. + + >>> run(argv=["nosetests", "-v", "--with-todo", "--stop", todo_test], + ... plugins=[TodoPlugin()]) # doctest: +REPORT_NDIFF + errorclass_failing_test.test_todo ... TODO: fix me + <BLANKLINE> + ====================================================================== + TODO: errorclass_failing_test.test_todo + ---------------------------------------------------------------------- + Traceback (most recent call last): + ... + Todo: fix me + <BLANKLINE> + ---------------------------------------------------------------------- + Ran 1 test in ...s + <BLANKLINE> + FAILED (TODO=1) + + +With a false isfailure, when the errorclass' exception is caught by +nose, tracebacks are not printed, and the test run does not stop. + + >>> run(argv=["nosetests", "-v", "--with-non-failure-todo", "--stop", + ... todo_test], + ... plugins=[NonFailureTodoPlugin()]) # doctest: +REPORT_NDIFF + errorclass_failing_test.test_todo ... TODO: fix me + errorclass_failing_test.test_2 ... ok + <BLANKLINE> + ---------------------------------------------------------------------- + Ran 2 tests in ...s + <BLANKLINE> + OK + + +Exception detail strings of errorclass errors are always printed when +-v is in effect, whether the errorclass is failure or non-failure. +Note that exception detail strings may have more than one line. + + >>> run(argv=["nosetests", "-v", "--with-todo", misc_test], + ... plugins=[TodoPlugin(), Skip(), Deprecated()]) + ... # doctest: +REPORT_NDIFF + errorclass_tests.test_todo ... TODO: fix me + errorclass_tests.test_2 ... ok + errorclass_tests.test_3 ... SKIP: skipety-skip + errorclass_tests.test_4 ... SKIP + errorclass_tests.test_5 ... DEPRECATED: spam + eggs + <BLANKLINE> + spam + errorclass_tests.test_6 ... DEPRECATED: spam + <BLANKLINE> + ====================================================================== + TODO: errorclass_tests.test_todo + ---------------------------------------------------------------------- + Traceback (most recent call last): + ... + Todo: fix me + <BLANKLINE> + ---------------------------------------------------------------------- + Ran 6 tests in ...s + <BLANKLINE> + FAILED (TODO=1) + +Without -v, the exception detail strings only appear in failure +errorclass tracebacks + + >>> run(argv=["nosetests", "--with-todo", misc_test], + ... plugins=[TodoPlugin(), Skip(), Deprecated()]) + ... # doctest: +REPORT_NDIFF + T.SSDD + ====================================================================== + TODO: errorclass_tests.test_todo + ---------------------------------------------------------------------- + Traceback (most recent call last): + ... + Todo: fix me + <BLANKLINE> + ---------------------------------------------------------------------- + Ran 6 tests in ...s + <BLANKLINE> + FAILED (TODO=1) + +>>> sys.path.remove(support) diff --git a/functional_tests/doc_tests/test_issue142/support/errorclass_failing_test.py b/functional_tests/doc_tests/test_issue142/support/errorclass_failing_test.py new file mode 100644 index 0000000..fae3c75 --- /dev/null +++ b/functional_tests/doc_tests/test_issue142/support/errorclass_failing_test.py @@ -0,0 +1,7 @@ +from errorclass_failure_plugin import Todo + +def test_todo(): + raise Todo("fix me") + +def test_2(): + pass diff --git a/functional_tests/doc_tests/test_issue142/support/errorclass_failure_plugin.py b/functional_tests/doc_tests/test_issue142/support/errorclass_failure_plugin.py new file mode 100644 index 0000000..927c986 --- /dev/null +++ b/functional_tests/doc_tests/test_issue142/support/errorclass_failure_plugin.py @@ -0,0 +1,16 @@ +from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin + +class Todo(Exception): + pass + +class TodoPlugin(ErrorClassPlugin): + + name = "todo" + + todo = ErrorClass(Todo, label='TODO', isfailure=True) + +class NonFailureTodoPlugin(ErrorClassPlugin): + + name = "non-failure-todo" + + todo = ErrorClass(Todo, label='TODO', isfailure=False) diff --git a/functional_tests/doc_tests/test_issue142/support/errorclass_tests.py b/functional_tests/doc_tests/test_issue142/support/errorclass_tests.py new file mode 100644 index 0000000..4981224 --- /dev/null +++ b/functional_tests/doc_tests/test_issue142/support/errorclass_tests.py @@ -0,0 +1,20 @@ +from errorclass_failure_plugin import Todo +from nose import SkipTest, DeprecatedTest + +def test_todo(): + raise Todo('fix me') + +def test_2(): + pass + +def test_3(): + raise SkipTest('skipety-skip') + +def test_4(): + raise SkipTest() + +def test_5(): + raise DeprecatedTest('spam\neggs\n\nspam') + +def test_6(): + raise DeprecatedTest('spam') |