Open GoogleCodeExporter opened 9 years ago
So:
mock.assert_called_once()
mock.assret_called_once_with()
would then raise AttributeError instead of silently working.
Original comment by fuzzyman
on 10 Aug 2013 at 7:04
(The regex would be in attribute lookup.)
I *am* proposing it be on by default.
Original comment by fuzzyman
on 10 Aug 2013 at 7:07
Yes, please. Have bitten by it multiple times..
Original comment by fungusak...@gmail.com
on 10 Aug 2013 at 10:01
Here is an example from a popular repository (Celery) of this problem:
https://github.com/celery/celery/blob/fa363ac44df5651caad236f9ccf913e6077d5bfd/c
elery/tests/backends/test_mongodb.py#L179
It goes without anyone noticing because it always passes tests.
Original comment by alan.ham...@gmail.com
on 23 Jan 2014 at 3:22
This bug has catastrophic effects and I believe it is a very wide reaching
(silent) problem.
Our codebase was affected with this problem. There were hundreds of tests that
were assumed passing, but the Mock was just absorbing the assert calls as mock
calls. The root cause being the double duty of the Mock both accepting mock
calls and assert calls.
The ideal solution being to introduce an expectation class.
e.g. expect(my_mock).toHaveBeenCalledWith()
In its absence I implemented a check in the Mock class to check the attribute
name before creating a child mock. If the attribute name starts with something
that looks like an assert call (e.g. 'assert', 'asssert', 'asert', 'assret',
etc.) then it raises an exception.
I think this is a very important bug to fix and would be happy to help with a
solution.
Thanks,
Wes
Original comment by he...@wesalvaro.com
on 21 Jan 2015 at 1:03
Original issue reported on code.google.com by
fuzzyman
on 10 Aug 2013 at 7:03