From 22b66b2ed698c3f161dcaf6f00c1d999a4a9fb87 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 6 Sep 2024 12:17:47 -0500 Subject: [PATCH] PYTHON-4695 Fix test event loop policy and improve error traceback for ClientBulkWriteException (#1828) --- pymongo/_client_bulk_shared.py | 2 ++ pyproject.toml | 1 + test/asynchronous/conftest.py | 2 ++ test/conftest.py | 2 ++ 4 files changed, 7 insertions(+) diff --git a/pymongo/_client_bulk_shared.py b/pymongo/_client_bulk_shared.py index 4dd1af210..649f1c6aa 100644 --- a/pymongo/_client_bulk_shared.py +++ b/pymongo/_client_bulk_shared.py @@ -74,4 +74,6 @@ def _throw_client_bulk_write_exception( "to your connection string." ) raise OperationFailure(errmsg, code, full_result) + if isinstance(full_result["error"], BaseException): + raise ClientBulkWriteException(full_result, verbose_results) from full_result["error"] raise ClientBulkWriteException(full_result, verbose_results) diff --git a/pyproject.toml b/pyproject.toml index 8452bfe95..225be8e1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,6 +74,7 @@ addopts = ["-ra", "--strict-config", "--strict-markers", "--junitxml=xunit-resul testpaths = ["test"] log_cli_level = "INFO" faulthandler_timeout = 1500 +asyncio_default_fixture_loop_scope = "session" xfail_strict = true filterwarnings = [ "error", diff --git a/test/asynchronous/conftest.py b/test/asynchronous/conftest.py index e443dff6c..c08f224ab 100644 --- a/test/asynchronous/conftest.py +++ b/test/asynchronous/conftest.py @@ -17,6 +17,8 @@ def event_loop_policy(): # has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240) # We explicitly use a different loop implementation here to prevent that issue if sys.platform == "win32": + # Needed for Python 3.8. + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) return asyncio.WindowsSelectorEventLoopPolicy() # type: ignore[attr-defined] return asyncio.get_event_loop_policy() diff --git a/test/conftest.py b/test/conftest.py index a3d954c7c..ca817a5a6 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -15,6 +15,8 @@ def event_loop_policy(): # has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240) # We explicitly use a different loop implementation here to prevent that issue if sys.platform == "win32": + # Needed for Python 3.8. + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) return asyncio.WindowsSelectorEventLoopPolicy() # type: ignore[attr-defined] return asyncio.get_event_loop_policy()