psycopg.git / summary / log / commit / refs

commit    65a477ee4a9c17bfb4166bcbb3fe83dc73fc4d03
Author:   Denis Laxalde <denis.laxalde@dalibo.com>
Date:     Sun Feb 05 17:40:16 2023 +0000

    test: use Windows asyncio policy in "non-asyncio" pool tests
    
    In commit b6cc8343159fc0a27365e09a3beef06433f3f1b5, we drop the global
    asyncio.set_event_loop_policy() for Windows in conftest.py, replacing it
    with asyncio_options to be used by the anyio test runner. However, test
    cases in test_pool_async_noasyncio.py are not "async def" so they would
    not use that anyio runner (nor did they use pytest-asyncio's runner
    before); but they need the event loop policy for Windows still.
    Accordingly, we configure the loop from "anyio_backend_options" in
    asyncio_run() fixture.


tests/pool/test_pool_async_noasyncio.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/pool/test_pool_async_noasyncio.py b/tests/pool/test_pool_async_noasyncio.py index f6e34e47..982b9288 100644 --- a/tests/pool/test_pool_async_noasyncio.py +++ b/tests/pool/test_pool_async_noasyncio.py @@ -61,12 +61,18 @@ def test_cant_create_open_outside_loop(dsn): @pytest.fixture -def asyncio_run(recwarn): +def asyncio_run(anyio_backend_options, recwarn): """Fixture reuturning asyncio.run, but managing resources at exit. In certain runs, fd objects are leaked and the error will only be caught downstream, by some innocent test calling gc_collect(). """ + try: + policy = anyio_backend_options["policy"] + except KeyError: + pass + else: + asyncio.set_event_loop_policy(policy) recwarn.clear() try: yield asyncio.run [parent: b6cc8343159f]