lundi 23 mars 2015

Python mock swallows exceptions

I'm using python mock library (python 2.7, mock==1.0.1) and when mocking out certain parts of code that I'm testing mock is swallowing exceptions for some reason.


Below is an example:



#test.py
from something import main_func
class TestCase(test.TestCase):
@mock.patch('something.somewhere')
def test_something(mock_somewhere):
main_func()


#something.py
def somewhere(param):
print param

def main_func():
somewhere(None.missing_something)


So AttributeError should be raised right? This test is passing on my machine, in reality the code is more complicated, a Django Model is supposed to be saved and existing. The test is failing because the model doesn't exist.


If I insert an import ipdb; ipdb.set_trace() just before somewhere(None.missing_method) then I can see the AttributeException is raised but it doesn't show up in the test.


Any ideas?


Aucun commentaire:

Enregistrer un commentaire