Issue #23661: unittest.mock side_effects can now be exceptions again.
This was a regression vs Python 3.4. Patch from Ignacio Rossi
This commit is contained in:
parent
47066ee3db
commit
f58f88c4c7
|
@ -506,7 +506,8 @@ class NonCallableMock(Base):
|
||||||
if delegated is None:
|
if delegated is None:
|
||||||
return self._mock_side_effect
|
return self._mock_side_effect
|
||||||
sf = delegated.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)
|
sf = _MockIter(sf)
|
||||||
delegated.side_effect = sf
|
delegated.side_effect = sf
|
||||||
return sf
|
return sf
|
||||||
|
|
|
@ -173,6 +173,15 @@ class MockTest(unittest.TestCase):
|
||||||
self.assertEqual([mock(), mock(), mock()], [3, 2, 1],
|
self.assertEqual([mock(), mock(), mock()], [3, 2, 1],
|
||||||
"callable side effect not used correctly")
|
"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,
|
@unittest.skipUnless('java' in sys.platform,
|
||||||
'This test only applies to Jython')
|
'This test only applies to Jython')
|
||||||
def test_java_exception_side_effect(self):
|
def test_java_exception_side_effect(self):
|
||||||
|
|
|
@ -1581,3 +1581,4 @@ Tarek Ziadé
|
||||||
Gennadiy Zlobin
|
Gennadiy Zlobin
|
||||||
Doug Zongker
|
Doug Zongker
|
||||||
Peter Åstrand
|
Peter Åstrand
|
||||||
|
Ignacio Rossi
|
||||||
|
|
|
@ -17,6 +17,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #23661: unittest.mock side_effects can now be exceptions again. This
|
||||||
|
was a regression vs Python 3.4. Patch from Ignacio Rossi
|
||||||
|
|
||||||
- Issue #24608: chunk.Chunk.read() now always returns bytes, not str.
|
- Issue #24608: chunk.Chunk.read() now always returns bytes, not str.
|
||||||
|
|
||||||
- Issue #18684: Fixed reading out of the buffer in the re module.
|
- Issue #18684: Fixed reading out of the buffer in the re module.
|
||||||
|
|
Loading…
Reference in New Issue