Skip to content

Commit 22b66b2

Browse files
authored
PYTHON-4695 Fix test event loop policy and improve error traceback for ClientBulkWriteException (mongodb#1828)
1 parent 4e10223 commit 22b66b2

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

pymongo/_client_bulk_shared.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,6 @@ def _throw_client_bulk_write_exception(
7474
"to your connection string."
7575
)
7676
raise OperationFailure(errmsg, code, full_result)
77+
if isinstance(full_result["error"], BaseException):
78+
raise ClientBulkWriteException(full_result, verbose_results) from full_result["error"]
7779
raise ClientBulkWriteException(full_result, verbose_results)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ addopts = ["-ra", "--strict-config", "--strict-markers", "--junitxml=xunit-resul
7474
testpaths = ["test"]
7575
log_cli_level = "INFO"
7676
faulthandler_timeout = 1500
77+
asyncio_default_fixture_loop_scope = "session"
7778
xfail_strict = true
7879
filterwarnings = [
7980
"error",

test/asynchronous/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def event_loop_policy():
1717
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
1818
# We explicitly use a different loop implementation here to prevent that issue
1919
if sys.platform == "win32":
20+
# Needed for Python 3.8.
21+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
2022
return asyncio.WindowsSelectorEventLoopPolicy() # type: ignore[attr-defined]
2123

2224
return asyncio.get_event_loop_policy()

test/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def event_loop_policy():
1515
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
1616
# We explicitly use a different loop implementation here to prevent that issue
1717
if sys.platform == "win32":
18+
# Needed for Python 3.8.
19+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
1820
return asyncio.WindowsSelectorEventLoopPolicy() # type: ignore[attr-defined]
1921

2022
return asyncio.get_event_loop_policy()

0 commit comments

Comments
 (0)