Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mocker.stub() is a coroutine function #375

Open
AstraLuma opened this issue Jul 24, 2023 · 1 comment
Open

mocker.stub() is a coroutine function #375

AstraLuma opened this issue Jul 24, 2023 · 1 comment
Labels

Comments

@AstraLuma
Copy link

def test_icf_sync(mocker):
    func = mocker.stub('func')
    assert not inspect.iscoroutinefunction(func)


def test_icf_async(mocker):
    func = mocker.async_stub('func')
    assert inspect.iscoroutinefunction(func)

Expected: mocker.stub() returns something that doesn't resemble a coroutine.

Observed: mocker.stub() is detected as a coroutine.

@nicoddemus
Copy link
Member

Hi @AstraLuma,

mocker.stub is just a thin wrapper which calls unittest.mock.MagicMock:

return cast(
unittest.mock.MagicMock,
self.mock_module.MagicMock(spec=lambda *args, **kwargs: None, name=name),
)

Can you replace your mocker.stub call by unittest.mock.MagicMock and see if you have the same behavior? If you do then the behavior is expected, and you can raise the question upstream to see if this is intended by unittest.mock or it should behave differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants