python something like assertFunctionNotCalled?
Question: Edit: This question refers to python 3.5

In python unit testing, is there a way to assert that a given block of code is
not called?

I have a function I am testing that can follow either of two branches: a
faster, more reliable branch if the user has logged in before, or a slower
less reliable branch if this is their first visit. Basically, the first time a
user logs in, the program has to request information about them from separate
server, which can be slow (and, occasionally, down). Once it has the
information, however, it caches it locally and should just use the local cache
for the data on subsequent logins.

The end result of the function is the same either way, so there is no way for
me to know which code branch it took to get the information by simply looking
at the output of the function. So ideally I'd like to be able to do
effectively an `assertFunctionNotCalled` to test that it is pulling from the
local cache on the second (and subsequent) login attempt. How should I best
test this?


Answer: Use the bool called like so:

    
    
    from mock import patch
    with patch('something') as mock_something:
        self.assertFalse(mock_something.called)
    

