Skip to content

mocker.stub() is a coroutine function #375

Open

Description

@AstraLuma
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.

Activity

  1. nicoddemus commented on Jul 25, 2023

    @nicoddemus
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions