mirror of
https://github.com/python/cpython.git
synced 2025-12-11 19:40:17 +00:00
Rename "exc_value" attribute on assertRaises context manager to "exception".
This commit is contained in:
parent
4ad752d70f
commit
dc3694bee0
3 changed files with 5 additions and 13 deletions
|
|
@ -898,13 +898,13 @@ Test cases
|
||||||
do_something()
|
do_something()
|
||||||
|
|
||||||
The context manager will store the caught exception object in its
|
The context manager will store the caught exception object in its
|
||||||
:attr:`exc_value` attribute. This can be useful if the intention
|
:attr:`exception` attribute. This can be useful if the intention
|
||||||
is to perform additional checks on the exception raised::
|
is to perform additional checks on the exception raised::
|
||||||
|
|
||||||
with self.assertRaises(SomeException) as cm:
|
with self.assertRaises(SomeException) as cm:
|
||||||
do_something()
|
do_something()
|
||||||
|
|
||||||
the_exception = cm.exc_value
|
the_exception = cm.exception
|
||||||
self.assertEqual(the_exception.error_code, 3)
|
self.assertEqual(the_exception.error_code, 3)
|
||||||
|
|
||||||
.. versionchanged:: 2.7
|
.. versionchanged:: 2.7
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ Still need testing:
|
||||||
TestCase.{assert,fail}* methods (some are tested implicitly)
|
TestCase.{assert,fail}* methods (some are tested implicitly)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from StringIO import StringIO
|
|
||||||
import __builtin__
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -626,7 +624,6 @@ class Test_TestLoader(TestCase):
|
||||||
# a good chance that it won't be imported when this test is run
|
# a good chance that it won't be imported when this test is run
|
||||||
module_name = 'audioop'
|
module_name = 'audioop'
|
||||||
|
|
||||||
import sys
|
|
||||||
if module_name in sys.modules:
|
if module_name in sys.modules:
|
||||||
del sys.modules[module_name]
|
del sys.modules[module_name]
|
||||||
|
|
||||||
|
|
@ -1014,7 +1011,6 @@ class Test_TestLoader(TestCase):
|
||||||
# a good chance that it won't be imported when this test is run
|
# a good chance that it won't be imported when this test is run
|
||||||
module_name = 'audioop'
|
module_name = 'audioop'
|
||||||
|
|
||||||
import sys
|
|
||||||
if module_name in sys.modules:
|
if module_name in sys.modules:
|
||||||
del sys.modules[module_name]
|
del sys.modules[module_name]
|
||||||
|
|
||||||
|
|
@ -1962,8 +1958,6 @@ class Test_TestResult(TestCase):
|
||||||
# methods. Contains formatted tracebacks instead
|
# methods. Contains formatted tracebacks instead
|
||||||
# of sys.exc_info() results."
|
# of sys.exc_info() results."
|
||||||
def test_addFailure(self):
|
def test_addFailure(self):
|
||||||
import sys
|
|
||||||
|
|
||||||
class Foo(unittest.TestCase):
|
class Foo(unittest.TestCase):
|
||||||
def test_1(self):
|
def test_1(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -2012,8 +2006,6 @@ class Test_TestResult(TestCase):
|
||||||
# methods. Contains formatted tracebacks instead
|
# methods. Contains formatted tracebacks instead
|
||||||
# of sys.exc_info() results."
|
# of sys.exc_info() results."
|
||||||
def test_addError(self):
|
def test_addError(self):
|
||||||
import sys
|
|
||||||
|
|
||||||
class Foo(unittest.TestCase):
|
class Foo(unittest.TestCase):
|
||||||
def test_1(self):
|
def test_1(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -2888,7 +2880,7 @@ test case
|
||||||
ctx = self.assertRaises(ExceptionMock)
|
ctx = self.assertRaises(ExceptionMock)
|
||||||
with ctx:
|
with ctx:
|
||||||
Stub(v)
|
Stub(v)
|
||||||
e = ctx.exc_value
|
e = ctx.exception
|
||||||
self.assertIsInstance(e, ExceptionMock)
|
self.assertIsInstance(e, ExceptionMock)
|
||||||
self.assertEqual(e.args[0], v)
|
self.assertEqual(e.args[0], v)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ class _AssertRaisesContext(object):
|
||||||
if not issubclass(exc_type, self.expected):
|
if not issubclass(exc_type, self.expected):
|
||||||
# let unexpected exceptions pass through
|
# let unexpected exceptions pass through
|
||||||
return False
|
return False
|
||||||
self.exc_value = exc_value #store for later retrieval
|
self.exception = exc_value # store for later retrieval
|
||||||
if self.expected_regexp is None:
|
if self.expected_regexp is None:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -389,7 +389,7 @@ class TestCase(object):
|
||||||
|
|
||||||
with self.assertRaises(SomeException) as cm:
|
with self.assertRaises(SomeException) as cm:
|
||||||
do_something()
|
do_something()
|
||||||
the_exception = cm.exc_value
|
the_exception = cm.exception
|
||||||
self.assertEqual(the_exception.error_code, 3)
|
self.assertEqual(the_exception.error_code, 3)
|
||||||
"""
|
"""
|
||||||
context = _AssertRaisesContext(excClass, self)
|
context = _AssertRaisesContext(excClass, self)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue