This test works.
def test_mock_ingest():
with mock.patch('app.ingest.ingest') as mock_ingest:
app.ingest.ingest('test-data', {'test-key': 'test-value'})
assert mock_ingest.call_count == 1
This test fails because mock_ingest.call_count = 0
def test_mock_ingest():
with mock.patch('app.ingest.ingest') as mock_ingest:
call_function_that_runs_async_code()
assert mock_ingest.call_count == 1
call_function_that_runs_async_code
calls the app.ingest.ingest
function.
I know because I can see that the test data is ingested.
But for some reason, mock_ingest.call_count
is still 0.
I think it has to do with the fact that the code that runs app.ingest.ingest
is async.
Edit:
I'm using python 3.8.
I also tried this without success:
```python
def test_mock_ingest():
with mock.patch('app.ingest.ingest', new_callable=mock.AsyncMock) as mock_ingest:
call_function_that_runs_async_code()
assert mock_ingest.call_count == 1