[TIP] mock and patch

Andrea Crotti andrea.crotti.0 at gmail.com
Thu Mar 22 03:37:57 PDT 2012


I was reading the doc at
http://www.voidspace.org.uk/python/mock/patch.html#where-to-patch

and so I tried this simple example, which I though would fail, because
from the doc I should instead patch 'module.getcwd' instead of
'os.getcwd'.


from os import getcwd

@mock.patch('os.getcwd')
def mycwd(_):
     print(os.getcwd())

mycwd()

<MagicMock name='getcwd()' id='32916368'>

But the patch actually works perfectly anyway, so am I misunderstanding
the doc or maybe it's not updated to the last (smarter) behaviour of the
mock library?



More information about the testing-in-python mailing list