Async fixture teardown

See original GitHub issue

Hi! I have question regarding how asynchronous fixture teardown (e.g. closing a connection that was open asynchronously) is supposed to work.

When I have a fixture such as:

@pytest.fixture(scope='session')
@async_generator
async def fixture():
    # ... async opening of a connection
    connection = await asyncpg.connect(...)
    await yield_(connection)
    await connection.close()

I am getting the following error: ValueError: Async generator fixture didn't stop.Yield only once.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dgilgecommented, Mar 2, 2018

Is there a solution for Python 3.5, too? Because it was nice to be able to confirm that packages work with Python 3.5, too.

2reactions
petr-kcommented, Feb 19, 2018

I can confirm that with Python 3.6, it works:

@pytest.yield_fixture()
async def fixture():
    # ...
    yield abc
    await abc.close()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it OK to use async TearDown in Selenium NUnit tests?
Yes. It is fine for any of the NUnit setup or teardown methods to be marked as async methods. There are many existing...
Read more >
Automating tests for async services using pytest
Setup and TearDown for pytest-asyncio: ... A way around is to create a class-level fixture, then auto-use it on your test cases to...
Read more >
async test patterns for Pytest - Anthony Shaw
I've found async testing in both pytest and unittest painful, confusing and ... The pytest-asyncio extension also enables async fixtures, ...
Read more >
Setup and Teardown - Jest
This can be especially bothersome when the setup is asynchronous, so you can't do it inline. Jest provides beforeAll and afterAll hooks to ......
Read more >
Testing with AnyIO — AnyIO 3.6.2 documentation
For async generator based fixtures, the test runner spawns a task that handles both the setup and teardown phases to enable context-sensitive code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found