-
Notifications
You must be signed in to change notification settings - Fork 162
Closed
Description
Sample test code:
tests.py
from unittest import mock
import pytest
import testmodule
@pytest.mark.asyncio
async def test_async_mock_patch_contextmanager():
with mock.patch('testmodule.foo') as foo_mock:
assert testmodule.foo is foo_mock
@pytest.mark.asyncio
@mock.patch('testmodule.foo')
async def test_async_mock_patch_decorator(foo_mock):
assert testmodule.foo is foo_mock # FAILS
def test_mock_patch_contextmanager():
with mock.patch('testmodule.foo') as foo_mock:
assert testmodule.foo is foo_mock
@mock.patch('testmodule.foo')
def test_mock_patch_decorator(foo_mock):
assert testmodule.foo is foo_mock
testmodule.py
def foo():
return 'Bar'
test_async_mock_patch_decorator
will fail, because testmodule.foo
is <function foo at ###>
, not <MagicMock name='foo' id='###'>
Tested this on python3.6 only.
UPDATE:
Seems that on python 3.5.2
there is no such bug. All tests succeeded.
afiram and samos123
Metadata
Metadata
Assignees
Labels
No labels