Skip to content

asynctest.patch is not respected in "with" block #153

@geoolekom

Description

@geoolekom

If you patch coroutine in setUp with MagicMock, you can't redefine it as CoroutineMock using "with" syntax. However, you can do it with decorator.

Here is a simple example to reproduce the situation.

class TestTest(asynctest.TestCase):
    def setUp(self):
        wrong_mock = mock.patch("some.service.coro")
        wrong_mock.start()

    @asynctest.patch("some.service.coro")
    def test_ok(self, coro_mock):
        assert isinstance(coro_mock, asynctest.CoroutineMock)

    def test_not_ok(self):
        with asynctest.patch("some.service.coro") as coro_mock:
            assert isinstance(coro_mock, asynctest.CoroutineMock)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions