Kaydet (Commit) a3fffb05 authored tarafından Robert Collins's avatar Robert Collins

Issue #23661: unittest.mock side_effects can now be exceptions again.

This was a regression vs Python 3.4. Patch from Ignacio Rossi
üst dc87e4b8
......@@ -506,7 +506,8 @@ class NonCallableMock(Base):
if delegated is None:
return self._mock_side_effect
sf = delegated.side_effect
if sf is not None and not callable(sf) and not isinstance(sf, _MockIter):
if (sf is not None and not callable(sf)
and not isinstance(sf, _MockIter) and not _is_exception(sf)):
sf = _MockIter(sf)
delegated.side_effect = sf
return sf
......
......@@ -173,6 +173,15 @@ class MockTest(unittest.TestCase):
self.assertEqual([mock(), mock(), mock()], [3, 2, 1],
"callable side effect not used correctly")
def test_autospec_side_effect_exception(self):
# Test for issue 23661
def f():
pass
mock = create_autospec(f)
mock.side_effect = ValueError('Bazinga!')
self.assertRaisesRegex(ValueError, 'Bazinga!', mock)
@unittest.skipUnless('java' in sys.platform,
'This test only applies to Jython')
def test_java_exception_side_effect(self):
......
......@@ -1582,3 +1582,4 @@ Tarek Ziadé
Gennadiy Zlobin
Doug Zongker
Peter Åstrand
Ignacio Rossi
......@@ -17,6 +17,9 @@ Library
for patterns that starts with capturing groups. Fast searching optimization
now can't be disabled at compile time.
- Issue #23661: unittest.mock side_effects can now be exceptions again. This
was a regression vs Python 3.4. Patch from Ignacio Rossi
What's New in Python 3.5.0 beta 4?
==================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment