Skip to content

Commit 1575e53

Browse files
authored
PYTHON-3409 Retry flakey CSOT tests twice (#1046)
1 parent 9ff0ac8 commit 1575e53

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

test/test_retryable_writes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ def setUpClass(cls):
471471
def test_RetryableWriteError_error_label(self):
472472
listener = OvertCommandListener()
473473
client = rs_or_single_client(retryWrites=True, event_listeners=[listener])
474+
self.addCleanup(client.close)
474475

475476
# Ensure collection exists.
476477
client.pymongo_test.testcoll.insert_one({})

test/unified_format.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import re
2626
import sys
2727
import time
28+
import traceback
2829
import types
2930
from collections import abc
3031
from test import (
@@ -1580,6 +1581,25 @@ def verify_outcome(self, spec):
15801581
self.assertListEqual(sorted_expected_documents, actual_documents)
15811582

15821583
def run_scenario(self, spec, uri=None):
1584+
if "csot" in self.id().lower():
1585+
# Retry CSOT tests up to 2 times to deal with flakey tests.
1586+
attempts = 3
1587+
for i in range(attempts):
1588+
try:
1589+
return self._run_scenario(spec, uri)
1590+
except AssertionError:
1591+
if i < attempts - 1:
1592+
print(
1593+
f"Retrying after attempt {i+1} of {self.id()} failed with:\n"
1594+
f"{traceback.format_exc()}"
1595+
)
1596+
self.setUp()
1597+
continue
1598+
raise
1599+
else:
1600+
self._run_scenario(spec, uri)
1601+
1602+
def _run_scenario(self, spec, uri=None):
15831603
# maybe skip test manually
15841604
self.maybe_skip_test(spec)
15851605

0 commit comments

Comments
 (0)