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

Inconsistent behavior for sync and async generator functions #642

Closed
seifertm opened this issue Oct 23, 2023 · 0 comments · Fixed by #643
Closed

Inconsistent behavior for sync and async generator functions #642

seifertm opened this issue Oct 23, 2023 · 0 comments · Fixed by #643
Milestone

Comments

@seifertm
Copy link
Contributor

Pytest no longer supports tests based generator functions and will xfail the respective test:

test_generator.py

def test_gen():
    yield
$ pytest test_generator.py 
============================================================================================================================ test session starts =============================================================================================================================
platform linux -- Python 3.11.6, pytest-7.4.2, pluggy-1.3.0
rootdir: /tmp/tst
plugins: asyncio-0.21.1
asyncio: mode=Mode.STRICT
collected 1 item                                                                                                                                                                                                                                                             

test_generator.py x                                                                                                                                                                                                                                                    [100%]

============================================================================================================================== warnings summary ==============================================================================================================================
test_generator.py:1
  test_generator.py:1: PytestCollectionWarning: yield tests were removed in pytest 4.0 - test_gen will be ignored
    def test_gen():

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================================================================= 1 xfailed, 1 warning in 0.15s ========================================================================================================================

Pytest-asyncio v0.21.1 simply refuses to take care of async generator functions, which causes pytest to complain about a missing plugin for async tests.

test_a.py

async def test_async_gen():
    yield
$ pytest --asyncio-mode=auto test_a.py
============================================================================================================================ test session starts =============================================================================================================================
platform linux -- Python 3.11.6, pytest-7.4.2, pluggy-1.3.0
rootdir: /tmp/tst
plugins: asyncio-0.21.1
asyncio: mode=Mode.AUTO
collected 1 item                                                                                                                                                                                                                                                             

test_a.py s                                                                                                                                                                                                                                                            [100%]

============================================================================================================================== warnings summary ==============================================================================================================================
test_a.py::test_async_gen
  /tmp/tst/venv/lib/python3.11/site-packages/_pytest/python.py:183: 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:
    - anyio
    - pytest-asyncio
    - pytest-tornasync
    - pytest-trio
    - pytest-twisted
    warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================================================================= 1 skipped, 1 warning in 0.03s ========================================================================================================================

Pytest-asyncio should handle tests based on asynchronous generator functions and raise a warning similar to pytest.

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

Successfully merging a pull request may close this issue.

1 participant