new bug introduced/functionality removed in upgrade from 1.3 to 1.4
See original GitHub issueI just upgraded from mockito-1.3.0 to mockito-1.4.0 and many of my tests began to fail. Here is “somewhat minimal” example of what kind of code used to work, but it doesn’t anymore (python 3.7.3):
from typing import Callable
from nose.tools import assert_equal
from mockito import mock, when
class _c(object):
def __init__(self, fn: Callable[[int], str]) -> None:
self._fn = fn
def get_val(self, a: int) -> str:
return self._fn(a)
def test_foo():
x = mock()
c = _c(x.get_value)
when(x).get_value(10).thenReturn('foo')
assert_equal(c.get_val(10), 'foo')
result:
$ nosetests a.py
F
======================================================================
FAIL: a.test_foo
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/spurny/py-venv/wf3/lib/python3.7/site-packages/nose/case.py", line 198, in runTest
self.test(*self.arg)
File "/home/spurny/src-experiments/mockito-1.4-bug/a.py", line 18, in test_foo
assert_equal(c.get_val(10), 'foo')
AssertionError: None != 'foo'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
but if I mock the x.get_value
before creating c
:
...
def test_foo():
x = mock()
when(x).get_value(10).thenReturn('foo') # moved here from below `c = _c(...` line
c = _c(x.get_value)
assert_equal(c.get_val(10), 'foo')
then it works fine:
$ nosetests a.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Azure AD Connect: Upgrade from a previous version to the latest
Explains the different methods to upgrade to the latest release of Azure Active Directory Connect, including an in-place upgrade and a swing ...
Read more >What's new in 1.4.0 (January 22, 2022) - Pandas
The new function supports the method , ascending , and pct flags of ... introduced in Python 3.9 to remove pre-/suffixes from string-type...
Read more >WinBUGS - MRC Biostatistics Unit - University of Cambridge
Contents. Introduction to WinBUGS; Installing WinBUGS 1.4 in Windows. Obtaining the key for unrestricted use; Upgrading to version 1.4.3. Problems ...
Read more >What's New in SQLAlchemy 1.4?
ORM Query is internally unified with select, update, delete; 2.0 style execution ... this feature was first introduced in version 1.3 and is...
Read more >Changelog — JupyterHub 3.1.0 documentation
0 is a small release, fixing various bugs and introducing some small new features and metrics. See more details below. Thanks to many...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You mean a different way from your original example? Typically just pass in a
mock()
. Then early or late configuration works:In that case you can also turn on “strictness” so it has a better error message.
(Otherwise you always have the
None
is not ‘foo’ assertion error.)Perfect, thanks! I didn’t thought of mocking
__call__
…