Skip to content

pytest now skips async tests #7110

@red-eight

Description

@red-eight

Here's a simple test case:

import asyncio import asynctest async def my_async_function(a, b): asyncio.sleep(1) return a + b class TestMyFunctions(asynctest.TestCase): async def test_my_async_function(self): expected_value = 8 value = await my_async_function(4, 4) self.assertEqual(expected_value, value) 

Everything works using an older version of pytest (pytest-5.3.5).

(virtenv) me@me-Latitude-7490:~/src/quicktests/pytest_regression$ python -m pytest -vx =========================================================================================== test session starts ============================================================================================ platform linux -- Python 3.6.9, pytest-5.3.5, py-1.8.1, pluggy-0.13.1 -- /home/me/.virtualenvs/virtenv/bin/python cachedir: .pytest_cache rootdir: /home/me/src/quicktests/tests_pytest_regression collected 1 item test_simple.py::TestMyFunctions::test_my_async_function PASSED [100%] ============================================================================================ 1 passed in 0.04s ============================================================================================= 

For some reason, the test is skipped in newer versions of pytest.

(virtenv) me@me-Latitude-7490:~/src/quicktests/pytest_regression$ pip install pytest --upgrade (virtenv) me@me-Latitude-7490:~/src/quicktests/pytest_regression$ python -m pytest -vx =========================================================================================== test session starts ============================================================================================ platform linux -- Python 3.6.9, pytest-5.4.1, py-1.8.1, pluggy-0.13.1 -- /home/me/.virtualenvs/virtenv/bin/python cachedir: .pytest_cache rootdir: /home/me/src/quicktests/tests_pytest_regression collected 1 item test_simple.py::TestMyFunctions::test_my_async_function SKIPPED [100%] ============================================================================================= warnings summary ============================================================================================= test_simple.py::TestMyFunctions::test_my_async_function /home/me/.virtualenvs/virtenv/lib/python3.6/site-packages/_pytest/python.py:171: PytestUnhandledCoroutineWarning: async def functions are not natively supported and have been skipped. You need to install a suitable plugin for your async framework, for example: - pytest-asyncio - pytest-trio - pytest-tornasync - pytest-twisted warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid))) -- Docs: https://docs.pytest.org/en/latest/warnings.html 

Also, it seems like AioHTTPTestCase tests are NOT skipped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: unittestrelated to the unittest integration builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions