I have a method that does the following:
import os
...
if not os.path.exists(dirpath):
os.makedirs(dirpath)
I'm trying to mock the makedirs
and path.exists
but when I do this with patch
the mocks conflict:
@patch('os.makedirs')
@patch('os.path.exists')
def test_foo(self, makedirs, exists):
c = Config()
c.foo()
assert makedirs.called
assert exists.called
If I disable either makedirs
or exists
they both work fine but have an issue when being used together.
I've also tried using with patch('os.makedirs') as makedirs:
syntax which doesn't change anything.
Does anyone know why they are conflicting or what I can do to resolve this?
Thanks!