From eeff50f2b88b8a678b0a1e6776e5ff7aa1e996b5 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 16 Jun 2026 15:41:55 -0400 Subject: [PATCH 1/3] PYTHON-5886 - Fix synchro bug caused by ruff upgrade --- test/asynchronous/test_pooling.py | 6 +++--- test/asynchronous/utils_spec_runner.py | 2 +- test/test_client_metadata.py | 2 +- test/test_encryption.py | 2 +- test/test_pooling.py | 6 +++--- test/utils_spec_runner.py | 2 +- tools/synchro.py | 28 ++++++++------------------ 7 files changed, 18 insertions(+), 30 deletions(-) diff --git a/test/asynchronous/test_pooling.py b/test/asynchronous/test_pooling.py index a35ee3eecf..96b603ec10 100644 --- a/test/asynchronous/test_pooling.py +++ b/test/asynchronous/test_pooling.py @@ -346,13 +346,13 @@ async def test_no_wait_queue_timeout(self): async with pool.checkout() as s1: t = SocketGetter(self.c, pool) await t.start() - while t.state != "get_socket": # noqa: ASYNC110 + while t.state != "get_socket": # noqa: ASYNC110, RUF100 await asyncio.sleep(0.1) await asyncio.sleep(1) self.assertEqual(t.state, "get_socket") - while t.state != "connection": # noqa: ASYNC110 + while t.state != "connection": # noqa: ASYNC110, RUF100 await asyncio.sleep(0.1) self.assertEqual(t.state, "connection") @@ -521,7 +521,7 @@ async def test_pool_backpressure_preserves_existing_connections(self): await coll.insert_many([{"x": 1} for _ in range(10)]) t = SocketGetter(self.c, pool) await t.start() - while t.state != "connection": # noqa: ASYNC110 + while t.state != "connection": # noqa: ASYNC110, RUF100 await asyncio.sleep(0.1) assert not t.sock.conn_closed() diff --git a/test/asynchronous/utils_spec_runner.py b/test/asynchronous/utils_spec_runner.py index 2d573065d6..e93bab269b 100644 --- a/test/asynchronous/utils_spec_runner.py +++ b/test/asynchronous/utils_spec_runner.py @@ -160,7 +160,7 @@ async def _create_tests(self): dirname = os.path.split(dirpath)[-1] for filename in filenames: - with open(os.path.join(dirpath, filename)) as scenario_stream: # noqa: ASYNC230 + with open(os.path.join(dirpath, filename)) as scenario_stream: # noqa: ASYNC230, RUF100 # Use tz_aware=False to match how CodecOptions decodes # dates. opts = json_util.JSONOptions(tz_aware=False) diff --git a/test/test_client_metadata.py b/test/test_client_metadata.py index cbb0b1e6b0..47a37b2151 100644 --- a/test/test_client_metadata.py +++ b/test/test_client_metadata.py @@ -193,7 +193,7 @@ def test_doesnt_update_established_connections(self): ) # send initial metadata - name, version, platform, _ = self.send_ping_and_get_metadata(client, True) + name, version, platform, _metadata = self.send_ping_and_get_metadata(client, True) self.assertIsNotNone(name) self.assertIsNotNone(version) self.assertIsNotNone(platform) diff --git a/test/test_encryption.py b/test/test_encryption.py index 3bb6e767b4..dd6545e074 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -2904,7 +2904,7 @@ def encrypt_and_cast(i): EncryptionError, "expected matching 'min' and value type. Got range option" ): self.client_encryption.encrypt( - 6 if cast_func is not int else float(6), + 6 if cast_func is int else float(6), key_id=self.key1_id, algorithm=Algorithm.RANGE, contention_factor=0, diff --git a/test/test_pooling.py b/test/test_pooling.py index 3a150ad34c..47266dd166 100644 --- a/test/test_pooling.py +++ b/test/test_pooling.py @@ -346,13 +346,13 @@ def test_no_wait_queue_timeout(self): with pool.checkout() as s1: t = SocketGetter(self.c, pool) t.start() - while t.state != "get_socket": + while t.state != "get_socket": # noqa: ASYNC110, RUF100 time.sleep(0.1) time.sleep(1) self.assertEqual(t.state, "get_socket") - while t.state != "connection": + while t.state != "connection": # noqa: ASYNC110, RUF100 time.sleep(0.1) self.assertEqual(t.state, "connection") @@ -519,7 +519,7 @@ def test_pool_backpressure_preserves_existing_connections(self): coll.insert_many([{"x": 1} for _ in range(10)]) t = SocketGetter(self.c, pool) t.start() - while t.state != "connection": + while t.state != "connection": # noqa: ASYNC110, RUF100 time.sleep(0.1) assert not t.sock.conn_closed() diff --git a/test/utils_spec_runner.py b/test/utils_spec_runner.py index f92533a9d4..5c63cd08c4 100644 --- a/test/utils_spec_runner.py +++ b/test/utils_spec_runner.py @@ -160,7 +160,7 @@ def _create_tests(self): dirname = os.path.split(dirpath)[-1] for filename in filenames: - with open(os.path.join(dirpath, filename)) as scenario_stream: # noqa: RUF100 + with open(os.path.join(dirpath, filename)) as scenario_stream: # noqa: ASYNC230, RUF100 # Use tz_aware=False to match how CodecOptions decodes # dates. opts = json_util.JSONOptions(tz_aware=False) diff --git a/tools/synchro.py b/tools/synchro.py index a8af3876eb..6e641a9218 100644 --- a/tools/synchro.py +++ b/tools/synchro.py @@ -171,22 +171,14 @@ if not Path.exists(Path(_gridfs_dest_base)): Path.mkdir(Path(_gridfs_dest_base)) -async_files = [ - _pymongo_base + str(f) - for f in Path.iterdir(Path(_pymongo_base)) - if (Path(_pymongo_base) / f).is_file() -] +async_files = [_pymongo_base + f.name for f in Path(_pymongo_base).iterdir() if f.is_file()] -gridfs_files = [ - _gridfs_base + str(f) - for f in Path.iterdir(Path(_gridfs_base)) - if (Path(_gridfs_base) / f).is_file() -] +gridfs_files = [_gridfs_base + f.name for f in Path(_gridfs_base).iterdir() if f.is_file()] def async_only_test(f: Path) -> bool: """Return True for async tests that should not be converted to sync.""" - return str(f) in [ + return f.name in [ "test_locks.py", "test_concurrency.py", "test_async_cancellation.py", @@ -197,9 +189,9 @@ def async_only_test(f: Path) -> bool: test_files = [ - _test_base + str(f) - for f in Path.iterdir(Path(_test_base)) - if (Path(_test_base) / f).is_file() and not async_only_test(f) + _test_base + f.name + for f in Path(_test_base).iterdir() + if f.is_file() and not async_only_test(f) ] # Add each asynchronized test here as part of the converting PR @@ -453,15 +445,11 @@ def main() -> None: unasync_directory(test_files, _test_base, _test_dest_base, replacements) sync_files = [ - _pymongo_dest_base + str(f) - for f in Path.iterdir(Path(_pymongo_dest_base)) - if (Path(_pymongo_dest_base) / f).is_file() + _pymongo_dest_base + f.name for f in Path(_pymongo_dest_base).iterdir() if f.is_file() ] sync_gridfs_files = [ - _gridfs_dest_base + str(f) - for f in Path.iterdir(Path(_gridfs_dest_base)) - if (Path(_gridfs_dest_base) / f).is_file() + _gridfs_dest_base + f.name for f in Path(_gridfs_dest_base).iterdir() if f.is_file() ] sync_test_files = [ _test_dest_base + f for f in converted_tests if (Path(_test_dest_base) / f).is_file() From b7468972cd6c9e1dfe45e2f27359252041d02318 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 16 Jun 2026 16:07:26 -0400 Subject: [PATCH 2/3] More fixes --- .evergreen/generated_configs/variants.yml | 18 +++++++++--------- .evergreen/scripts/generate_config_utils.py | 6 ++++-- test/asynchronous/test_encryption.py | 2 +- test/test_encryption.py | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.evergreen/generated_configs/variants.yml b/.evergreen/generated_configs/variants.yml index 4dd44b5048..b61dfcd51d 100644 --- a/.evergreen/generated_configs/variants.yml +++ b/.evergreen/generated_configs/variants.yml @@ -82,7 +82,7 @@ buildvariants: - name: .auth-aws display_name: Auth AWS Win64 run_on: - - windows-2022-latest-small + - windows-64-vsMulti-small tags: [] - name: auth-aws-macos tasks: @@ -206,7 +206,7 @@ buildvariants: - name: .test-non-standard !.pypy display_name: Encryption Win64 run_on: - - windows-2022-latest-small + - windows-64-vsMulti-small batchtime: 1440 expansions: TEST_NAME: encryption @@ -238,7 +238,7 @@ buildvariants: - name: .test-non-standard !.pypy display_name: Encryption crypt_shared Win64 run_on: - - windows-2022-latest-small + - windows-64-vsMulti-small batchtime: 1440 expansions: TEST_NAME: encryption @@ -280,7 +280,7 @@ buildvariants: - name: .test-standard-auth !.pypy .auth !.free-threaded display_name: Auth Enterprise Win64 run_on: - - windows-2022-latest-small + - windows-64-vsMulti-small expansions: TEST_NAME: enterprise_auth AUTH: auth @@ -393,7 +393,7 @@ buildvariants: - name: .ocsp-rsa !.ocsp-staple .4.4 display_name: OCSP Win64 run_on: - - windows-2022-latest-small + - windows-64-vsMulti-small batchtime: 10080 - name: ocsp-macos tasks: @@ -434,7 +434,7 @@ buildvariants: - name: "!.auth_oidc_remote .auth_oidc" display_name: Auth OIDC Win64 run_on: - - windows-2022-latest-small + - windows-64-vsMulti-small batchtime: 1440 # Perf tests @@ -473,7 +473,7 @@ buildvariants: - name: .test-standard !.pypy .async .replica_set-noauth-ssl display_name: PyOpenSSL Win64 run_on: - - windows-2022-latest-small + - rhel87-small batchtime: 1440 expansions: SUB_TEST_NAME: pyopenssl @@ -618,7 +618,7 @@ buildvariants: - name: .test-no-orchestration !.pypy display_name: "* Test Win64" run_on: - - windows-2022-latest-small + - windows-64-vsMulti-small tags: [standard-non-linux] - name: test-win32 tasks: @@ -667,7 +667,7 @@ buildvariants: - name: .test-numpy display_name: Test Numpy Win64 run_on: - - windows-2022-latest-small + - windows-64-vsMulti-small tags: [binary, vector] - name: test-numpy-win32 tasks: diff --git a/.evergreen/scripts/generate_config_utils.py b/.evergreen/scripts/generate_config_utils.py index 50fd8526aa..1c7a2f2e13 100644 --- a/.evergreen/scripts/generate_config_utils.py +++ b/.evergreen/scripts/generate_config_utils.py @@ -141,8 +141,10 @@ def create_variant( if version: expansions["VERSION"] = version # 8.0+ Windows builds must run on win-latest - if "win64" in display_name.lower() or ( - "win32" in display_name.lower() and version and version >= "8.0" + if ( + ("win64" in display_name.lower() or "win32" in display_name.lower()) + and version + and version >= "8.0" ): kwargs["run_on"] = HOSTS["win-latest"].run_on return create_variant_generic( diff --git a/test/asynchronous/test_encryption.py b/test/asynchronous/test_encryption.py index 86172b4993..57acf5824e 100644 --- a/test/asynchronous/test_encryption.py +++ b/test/asynchronous/test_encryption.py @@ -2922,7 +2922,7 @@ async def encrypt_and_cast(i): EncryptionError, "expected matching 'min' and value type. Got range option" ): await self.client_encryption.encrypt( - 6 if cast_func is int else float(6), + 6 if cast_func is not int else float(6), key_id=self.key1_id, algorithm=Algorithm.RANGE, contention_factor=0, diff --git a/test/test_encryption.py b/test/test_encryption.py index dd6545e074..3bb6e767b4 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -2904,7 +2904,7 @@ def encrypt_and_cast(i): EncryptionError, "expected matching 'min' and value type. Got range option" ): self.client_encryption.encrypt( - 6 if cast_func is int else float(6), + 6 if cast_func is not int else float(6), key_id=self.key1_id, algorithm=Algorithm.RANGE, contention_factor=0, From a7c62ba7ffb4ec98daa777109847b60f90308315 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 16 Jun 2026 16:22:08 -0400 Subject: [PATCH 3/3] Operator precedence --- .evergreen/generated_configs/variants.yml | 18 +++++++++--------- .evergreen/scripts/generate_config_utils.py | 6 ++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.evergreen/generated_configs/variants.yml b/.evergreen/generated_configs/variants.yml index b61dfcd51d..4dd44b5048 100644 --- a/.evergreen/generated_configs/variants.yml +++ b/.evergreen/generated_configs/variants.yml @@ -82,7 +82,7 @@ buildvariants: - name: .auth-aws display_name: Auth AWS Win64 run_on: - - windows-64-vsMulti-small + - windows-2022-latest-small tags: [] - name: auth-aws-macos tasks: @@ -206,7 +206,7 @@ buildvariants: - name: .test-non-standard !.pypy display_name: Encryption Win64 run_on: - - windows-64-vsMulti-small + - windows-2022-latest-small batchtime: 1440 expansions: TEST_NAME: encryption @@ -238,7 +238,7 @@ buildvariants: - name: .test-non-standard !.pypy display_name: Encryption crypt_shared Win64 run_on: - - windows-64-vsMulti-small + - windows-2022-latest-small batchtime: 1440 expansions: TEST_NAME: encryption @@ -280,7 +280,7 @@ buildvariants: - name: .test-standard-auth !.pypy .auth !.free-threaded display_name: Auth Enterprise Win64 run_on: - - windows-64-vsMulti-small + - windows-2022-latest-small expansions: TEST_NAME: enterprise_auth AUTH: auth @@ -393,7 +393,7 @@ buildvariants: - name: .ocsp-rsa !.ocsp-staple .4.4 display_name: OCSP Win64 run_on: - - windows-64-vsMulti-small + - windows-2022-latest-small batchtime: 10080 - name: ocsp-macos tasks: @@ -434,7 +434,7 @@ buildvariants: - name: "!.auth_oidc_remote .auth_oidc" display_name: Auth OIDC Win64 run_on: - - windows-64-vsMulti-small + - windows-2022-latest-small batchtime: 1440 # Perf tests @@ -473,7 +473,7 @@ buildvariants: - name: .test-standard !.pypy .async .replica_set-noauth-ssl display_name: PyOpenSSL Win64 run_on: - - rhel87-small + - windows-2022-latest-small batchtime: 1440 expansions: SUB_TEST_NAME: pyopenssl @@ -618,7 +618,7 @@ buildvariants: - name: .test-no-orchestration !.pypy display_name: "* Test Win64" run_on: - - windows-64-vsMulti-small + - windows-2022-latest-small tags: [standard-non-linux] - name: test-win32 tasks: @@ -667,7 +667,7 @@ buildvariants: - name: .test-numpy display_name: Test Numpy Win64 run_on: - - windows-64-vsMulti-small + - windows-2022-latest-small tags: [binary, vector] - name: test-numpy-win32 tasks: diff --git a/.evergreen/scripts/generate_config_utils.py b/.evergreen/scripts/generate_config_utils.py index 1c7a2f2e13..50fd8526aa 100644 --- a/.evergreen/scripts/generate_config_utils.py +++ b/.evergreen/scripts/generate_config_utils.py @@ -141,10 +141,8 @@ def create_variant( if version: expansions["VERSION"] = version # 8.0+ Windows builds must run on win-latest - if ( - ("win64" in display_name.lower() or "win32" in display_name.lower()) - and version - and version >= "8.0" + if "win64" in display_name.lower() or ( + "win32" in display_name.lower() and version and version >= "8.0" ): kwargs["run_on"] = HOSTS["win-latest"].run_on return create_variant_generic(