Hacker News new | ask | show | jobs
by f00_ 1916 days ago
assert on the call_count attribute of a mock instead of trying to use methods on it like .assert_called_once_with()

"a mock’s job is to say, “You got it, boss” whenever anyone calls it. It will do real work, like raising an exception, when one of its convenience methods is called, like assert_called_once_with. But it won’t do real work when you call a method that only resembles a convenience method, such as assert_called_once (no _with!)."

https://engineeringblog.yelp.com/2015/02/assert_called_once-...

1 comments

This behaviour has changed in Python 3.5 [1], and it was also backported to the mock package.

When unsafe=False (the default), accessing an attribute that begins with assert will raise an error.

[1]: https://docs.python.org/3/library/unittest.mock.html#the-moc...

> accessing an attribute that begins with assert

Or any of the names in this surprising hardcoded list of typos https://github.com/python/cpython/blob/fdb9efce6ac211f973088...

do you happen to know if this is true on mock==2.0?
Yes it looks as if that functionality is in 2.0, but the list of typos isn’t as extensive as in later versions.

https://mock.readthedocs.io/en/latest/changelog.html#and-ear...