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

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

Open
geoolekom opened this issue Aug 24, 2020 · 1 comment
Open

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

geoolekom opened this issue Aug 24, 2020 · 1 comment

Comments

@geoolekom
Copy link

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)
@pegasus430
Copy link

Lets try to test them.

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

No branches or pull requests

2 participants