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

[Main]: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited #6539

Closed
drew2a opened this issue Nov 10, 2021 · 1 comment · Fixed by #6540
Closed

[Main]: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited #6539

drew2a opened this issue Nov 10, 2021 · 1 comment · Fixed by #6540

Comments

@drew2a
Copy link
Contributor

drew2a commented Nov 10, 2021

I see random test failure for PR tests on Linux

https://jenkins-ci.tribler.org/job/GH_Tribler_PR_Tests/job/PR_linux_pytest/2449/testReport/junit/src.tribler-core.tribler_core.components.restapi.rest.tests/test_settings_endpoint/test_set_rate_settings/

Error Message
RuntimeError: 1 Runtime Warning,
/usr/lib/python3.8/weakref.py:131:coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
Stacktrace
pyfuncitem = <Function test_set_rate_settings>

    def pytest_pyfunc_call(pyfuncitem):  # type: ignore
        """
        Run coroutines in an event loop instead of a normal function call.
        """
        fast = pyfuncitem.config.getoption("--aiohttp-fast")
        if asyncio.iscoroutinefunction(pyfuncitem.function):
            existing_loop = pyfuncitem.funcargs.get('proactor_loop')\
                or pyfuncitem.funcargs.get('loop', None)
            with _runtime_warning_context():
                with _passthrough_loop_context(existing_loop, fast=fast) as _loop:
                    testargs = {arg: pyfuncitem.funcargs[arg]
                                for arg in pyfuncitem._fixtureinfo.argnames}
>                   _loop.run_until_complete(pyfuncitem.obj(**testargs))

/usr/local/lib/python3.8/dist-packages/aiohttp/pytest_plugin.py:170: 
Full error
Error Message
RuntimeError: 1 Runtime Warning,
/usr/lib/python3.8/weakref.py:131:coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
Stacktrace
pyfuncitem = <Function test_set_rate_settings>

    def pytest_pyfunc_call(pyfuncitem):  # type: ignore
        """
        Run coroutines in an event loop instead of a normal function call.
        """
        fast = pyfuncitem.config.getoption("--aiohttp-fast")
        if asyncio.iscoroutinefunction(pyfuncitem.function):
            existing_loop = pyfuncitem.funcargs.get('proactor_loop')\
                or pyfuncitem.funcargs.get('loop', None)
            with _runtime_warning_context():
                with _passthrough_loop_context(existing_loop, fast=fast) as _loop:
                    testargs = {arg: pyfuncitem.funcargs[arg]
                                for arg in pyfuncitem._fixtureinfo.argnames}
>                   _loop.run_until_complete(pyfuncitem.obj(**testargs))

/usr/local/lib/python3.8/dist-packages/aiohttp/pytest_plugin.py:170: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3.8/contextlib.py:120: in __exit__
    next(self.gen)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    @contextlib.contextmanager
    def _runtime_warning_context():  # type: ignore
        """
        Context manager which checks for RuntimeWarnings, specifically to
        avoid "coroutine 'X' was never awaited" warnings being missed.
    
        If RuntimeWarnings occur in the context a RuntimeError is raised.
        """
        with warnings.catch_warnings(record=True) as _warnings:
            yield
            rw = ['{w.filename}:{w.lineno}:{w.message}'.format(w=w)
                  for w in _warnings  # type: ignore
                  if w.category == RuntimeWarning]
            if rw:
>               raise RuntimeError('{} Runtime Warning{},\n{}'.format(
                    len(rw),
                    '' if len(rw) == 1 else 's',
                    '\n'.join(rw)
                ))
E               RuntimeError: 1 Runtime Warning,
E               /usr/lib/python3.8/weakref.py:131:coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

/usr/local/lib/python3.8/dist-packages/aiohttp/pytest_plugin.py:127: RuntimeError
@qstokkink
Copy link
Contributor

qstokkink commented Nov 10, 2021

There are only two parts of the codebase that use AsyncMock. One of them is test_get_events_has_undelivered_error.

The output is as follows:

test_events_endpoint.py::test_get_events_has_undelivered_error 

============================== 1 passed in 0.30s ===============================
sys:1: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Process finished with exit code 0
PASSED    [100%]

The test passes, but leaves behind AsyncMockMixin._execute_mock_call for another test (test_set_rate_settings) to fail on.

@drew2a drew2a self-assigned this Nov 10, 2021
@drew2a drew2a added this to the 7.12.0 December milestone Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants