derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

No way to assert call not made #159

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
There is currently no way to assert that a specific call has not been made. The 
workaround would be something like self.assertNotRaises(AssertionError, 
mock.assert_any_call(..._)) which is a bit awkward to write.

I can see two possible syntaxes:

1. self.assertTrue(not mock.has_any_call(....))
2. mock.assert_no_call_with(...)

Original issue reported on code.google.com by wich...@wiggy.net on 17 May 2012 at 12:00

GoogleCodeExporter commented 9 years ago
There's also:

    self.assertNotIn(call(1, 2, 3), mock.mock_calls)

Original comment by fuzzyman on 17 May 2012 at 12:02

GoogleCodeExporter commented 9 years ago
The workaround is 

self.assertFalse(mock.called)

but something like think looks much better:

mock.assert_not_called()

or event better for PEP8 joy:

mock.assertNotCalled()

Thanks!

Original comment by adiroi...@gmail.com on 4 Jul 2013 at 12:37

GoogleCodeExporter commented 9 years ago
Also useful for generating a helpful message (rather than "True is not False" 
or having to write your own).

Patch here: 
https://code.google.com/r/helen-mock/source/detail?r=75c2da89197361589e9b4e2a35b
a84aba68eb1c7&name=assert_not_called

I've also put in an assert_called function. i.e. the mock was called, there 
might have been args but the test doesn't care what they are.

Original comment by he...@rrdlabs.co.uk on 25 Aug 2014 at 12:30