2 new commits in pytest:
https://bitbucket.org/hpk42/pytest/commits/cf0ce46a5189/
Changeset: cf0ce46a5189
User: flub
Date: 2014-04-15 00:09:10
Summary: Improve error message if pytest.raises is used wrongly
If the type is not checked then an incomprehensible error will occur
later. This enforces the type and raies the same exception/msg as
CPython does in that case.
Docstring unmodified, just re-justified for pep8 compat.
Affected #: 2 files
diff -r a00590d97593d00163772511aca3149f7ef0bae2 -r
cf0ce46a5189c79bfab54eaab4b3fa6406e9c1ee _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -977,15 +977,16 @@
Performance note:
-----------------
- Similar to caught exception objects in Python, explicitly clearing local
- references to returned ``py.code.ExceptionInfo`` objects can help the
Python
- interpreter speed up its garbage collection.
+ Similar to caught exception objects in Python, explicitly clearing
+ local references to returned ``py.code.ExceptionInfo`` objects can
+ help the Python interpreter speed up its garbage collection.
- Clearing those references breaks a reference cycle (``ExceptionInfo`` -->
- caught exception --> frame stack raising the exception --> current frame
- stack --> local variables --> ``ExceptionInfo``) which makes Python keep
all
- objects referenced from that cycle (including all local variables in the
- current frame) alive until the next cyclic garbage collection run. See the
+ Clearing those references breaks a reference cycle
+ (``ExceptionInfo`` --> caught exception --> frame stack raising
+ the exception --> current frame stack --> local variables -->
+ ``ExceptionInfo``) which makes Python keep all objects referenced
+ from that cycle (including all local variables in the current
+ frame) alive until the next cyclic garbage collection run. See the
official Python ``try`` statement documentation for more detailed
information.
@@ -995,7 +996,16 @@
# we want to catch a AssertionError
# replace our subclass with the builtin one
# see https://bitbucket.org/hpk42/pytest/issue/176/pytestraises
- from _pytest.assertion.util import BuiltinAssertionError as
ExpectedException
+ from _pytest.assertion.util import BuiltinAssertionError \
+ as ExpectedException
+ msg = ("exceptions must be old-style classes or"
+ " derived from BaseException, not %s")
+ if isinstance(ExpectedException, tuple):
+ for exc in ExpectedException:
+ if not inspect.isclass(exc):
+ raise TypeError(msg % type(exc))
+ elif not inspect.isclass(ExpectedException):
+ raise TypeError(msg % type(ExpectedException))
if not args:
return RaisesContext(ExpectedException)
diff -r a00590d97593d00163772511aca3149f7ef0bae2 -r
cf0ce46a5189c79bfab54eaab4b3fa6406e9c1ee testing/python/raises.py
--- a/testing/python/raises.py
+++ b/testing/python/raises.py
@@ -62,3 +62,10 @@
'*3 passed*',
])
+ def test_noclass(self):
+ with pytest.raises(TypeError):
+ pytest.raises('wrong', lambda: None)
+
+ def test_tuple(self):
+ with pytest.raises((KeyError, ValueError)):
+ raise KeyError('oops')
https://bitbucket.org/hpk42/pytest/commits/9572842277fa/
Changeset: 9572842277fa
User: flub
Date: 2014-04-15 00:12:29
Summary: Changelog for issue 475
Affected #: 1 file
diff -r cf0ce46a5189c79bfab54eaab4b3fa6406e9c1ee -r
9572842277fa4cf0e9cac75684b4fb02c3927f4d CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,9 @@
NEXT (2.6)
-----------------------------------
+- fix issue 475: fail early and comprehensible if calling
+ pytest.raises with wrong exception type.
+
- change XPASS colour to yellow rather then red when tests are run
with -v.
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.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit