Allow use of custom mock implementations
See original GitHub issueWith the growing use of asyncio
, we need ways to mock Coroutines.
Currently, mock
and unittest.mock
do not support creating specs for coroutines (AsyncMock is being added in python 3.8).
As a work around, we’re using asynctest.mock
, which has the same interface as unittest.mock
, however this requires us to completely re-implement the __init__
method of MockFixture
, and removes the “hide traceback” functionality (though we don’t care too much about this).
This allows us to have both mocker
and async_mocker
fixtures.
TLDR To ease this usecase (and potentially others), Can support for defining a mock modules path from the config be added please?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Mock Functions - Jest
Mock functions allow you to test the links between code by erasing the actual implementation of a function, capturing calls to the function ......
Read more >How to change mock implementation on a per single test basis?
Use mockFn.mockImplementation(fn). import { funcToMock } from './somewhere'; jest.mock('./somewhere'); beforeEach(() => { funcToMock.
Read more >How to Mock a Single Function from a Module with Jest
Create a mock for the entire module. Tell that mock to use actual (non-mocked) implementations for everything. Mock the desired function of the ......
Read more >Stubbing and Mocking with Mockito and JUnit - Semaphore CI
This unit test is based on the doAnswer/when directives. Mockito allows us to override the answer to any method by implementing the Answer ......
Read more >Mocking different values for the same module using Jest
Learn how to use Jest mocking utilities to setup tests with different mock values. ... They allow you to isolate the code under...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
agree with your points on this. I think it’s probably best to wait until 3.8 for this library.
In terms of creating a new plugin, it might be better to try and get the fixtures into the
asynctest
library instead. Will close this issue for now.The hack we have in place works well enough for us until that time, and for our specific usecase, it will be an easy migration.
If anyone else stumbles on this issue, here is the hack:
FWIW,
AsyncMock
is now available as part of mocker from https://github.com/pytest-dev/pytest-mock/commit/449d3d038e076fcdbb860815d306d4a59db44141 with rich assert diff for assert helpers associated withAsyncMock