import asyncio
import logging
+import sys
from types import TracebackType
from typing import Any, AsyncIterator, Dict, Optional, Type, Union
from typing import cast, overload, TYPE_CHECKING
row_factory: Optional[AsyncRowFactory[Row]] = None,
**kwargs: Any,
) -> "AsyncConnection[Any]":
+
+ if sys.platform == "win32":
+ loop = asyncio.get_running_loop()
+ if isinstance(loop, asyncio.ProactorEventLoop):
+ raise e.InterfaceError(
+ "psycopg does not currently support running in async mode "
+ "on windows on the 'ProactorEventLoop'. "
+ "Please ensure that a compatible event loop is used, like "
+ "by setting ``asyncio.set_event_loop_policy`` to "
+ "WindowsSelectorEventLoopPolicy"
+ )
+
params = await cls._get_connection_params(conninfo, **kwargs)
conninfo = make_conninfo(**params)
return [f"asyncio loop: {loop}"]
-def pytest_runtest_setup(item):
- # Skip asyncio tests on Windows: they just don't seem to work
- if sys.platform == "win32":
- for mark in item.iter_markers(name="asyncio"):
- pytest.skip(f"cannot run asyncio tests on {sys.platform}")
-
-
@pytest.fixture
def retries(request):
"""Retry a block in a test a few times before giving up."""
@pytest.fixture
def event_loop(request):
"""Return the event loop to test asyncio-marked tests."""
+ # pytest-asyncio reset the the loop config after each test, so set
+ # set them each time
loop = request.config.getoption("--loop")
if loop == "uvloop":
else:
assert loop == "default"
+ if sys.platform == "win32":
+ asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()