I'm starting a small project in Python and I want to create a unittest with py.test.
I need to patch a pymongo
module or a MongoClient
class.
So I tried something like this:
@pytest.fixture(scope='module')
def mock_pymongo(monkeypatch):
monkeypatch.setattr('pymongo', mongomock)
or somthing like this :
@pytest.fixture(scope='class')
def mock_pymongo(monkeypatch):
monkeypatch.setattr('pymongo.mongo_client.MongoClient', mongomock.mongo_client.MongoClient)
now in both test I am doing I get a scope mismatch error
scopeMismatch: You tried to access the 'function' scoped fixture 'monkeypatch' with a 'module' scoped request object, involved factories
tests/test_1.py:17: def mock_pymongo(monkeypatch)
Maybe I'm using the right tool but is there any way using monkeypatch in order to mock class and module in my unit test?