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

Async tests no longer work on python 3.11 #111

Closed
soldag opened this issue Oct 18, 2023 · 0 comments · Fixed by #112
Closed

Async tests no longer work on python 3.11 #111

soldag opened this issue Oct 18, 2023 · 0 comments · Fixed by #112

Comments

@soldag
Copy link
Contributor

soldag commented Oct 18, 2023

Async test functions aren't awaited on python 3.11 when annotated with a DDT decorator. Consequently, such tests will always pass. This can be reproduced with the following minimal example:

import asyncio
from unittest import IsolatedAsyncioTestCase

from ddt import ddt, data


@ddt
class TestDdt(IsolatedAsyncioTestCase):
    @data(1)
    async def test_ddt(self, value: int) -> None:
        await asyncio.sleep(1)
        self.assertNotEqual(value, 1)

Executing this test case results in the following warnings:

==================================================================== test session starts =====================================================================
platform linux -- Python 3.11.5, pytest-7.4.2, pluggy-1.3.0
rootdir: /home/soldag/ddt-test
collected 1 item                                                                                                                                             

test_ddt.py .                                                                                                                                          [100%]

====================================================================== warnings summary ======================================================================
test_ddt.py::TestDdt::test_ddt_1_1
  /usr/lib/python3.11/unittest/async_case.py:90: RuntimeWarning: coroutine 'TestDdt.test_ddt' was never awaited
    if self._callMaybeAsync(method) is not None:
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

test_ddt.py::TestDdt::test_ddt_1_1
  /usr/lib/python3.11/unittest/case.py:678: DeprecationWarning: It is deprecated to return a value that is not None from a test case (<bound method TestDdt.test_ddt of <test_ddt.TestDdt testMethod=test_ddt_1_1>>)
    return self.run(*args, **kwds)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=============================================================== 1 passed, 2 warnings in 0.05s ================================================================
@wswld wswld linked a pull request Nov 6, 2023 that will close this issue
@wswld wswld closed this as completed in #112 Nov 8, 2023
wswld added a commit that referenced this issue Nov 8, 2023
* Add async flag when wrapping async function

* Pin Ubuntu version

* Pin Ubuntu version to 18.04

* Update Python action version

* Drop support for Python 2.7

* Fix async tests for python 3.7

---------

Co-authored-by: Vsevolod Glumov <seva17@gmail.com>
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

Successfully merging a pull request may close this issue.

1 participant