mardi 28 juillet 2015

Python: How to check that del instruction called?

I'd like to test function:

#foo_module.py
def foo(*args, **kwargs):
   bar = SomeClass(*args, **kwargs)
   # actions with bar
   del bar

I chose to test the mock library. My test looks like:

@mock.patch('path.to.foo_module.SomeClass')
def test_foo(self, mock_class):
    foo()
    mock_class.assert_called_once_with()

But how I can check that 'del bar' executed? Call of mock_class.return_value.__del__ raises AttributeError.

Aucun commentaire:

Enregistrer un commentaire