Closed muriloazevedotw closed 1 year ago
Sorry just saw this. I can only guess because I can't see the rest of the code under test. Often if you import like this:
from elasticsearch import foo
The the mock can't intercept calls to the class/function because it has already been imported.
This is a common problem with all mock libraries in python.
Is there a way to resolve it?
@mhkhodashahi I don't know what your specific problem is, maybe if you post some sample code on a new thread.
As for the OP's question,
Instead of
from foo import ReportRepository
# probably connect to real OpenSearch
ReportRepository()
Do this.
import foo
# probably connect to real OpenSearch
foo.ReportRepository()
I tried to use openmock with pytest, it's bit little different that the example on Readme, but I think should work.
Here's my code:
This test only pass if run opensearch server. Any suggestion?