Skip to content

Commit db1449b

Browse files
authoredApr 17, 2025··
PYTHON-5330 Convert no c extensions and doctests to use the standard test pattern (#2294)
1 parent 448c8e8 commit db1449b

File tree

12 files changed

+47
-109
lines changed

12 files changed

+47
-109
lines changed
 

‎.evergreen/generated_configs/functions.yml

-15
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,6 @@ functions:
8585
params:
8686
directory: src
8787

88-
# Run just script
89-
run just script:
90-
- command: subprocess.exec
91-
params:
92-
binary: bash
93-
args:
94-
- .evergreen/just.sh
95-
- ${JUSTFILE_TARGET}
96-
working_dir: src
97-
include_expansions_in_env:
98-
- AWS_ACCESS_KEY_ID
99-
- AWS_SECRET_ACCESS_KEY
100-
- AWS_SESSION_TOKEN
101-
type: test
102-
10388
# Run server
10489
run server:
10590
- command: subprocess.exec

‎.evergreen/generated_configs/tasks.yml

-9
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,6 @@ tasks:
734734
depends_on: [{ name: .server-version, variant: .coverage_tag, status: "*", patch_optional: true }]
735735
tags: [coverage]
736736

737-
# Doctest tests
738-
- name: test-doctests
739-
commands:
740-
- func: run server
741-
- func: run just script
742-
vars:
743-
JUSTFILE_TARGET: docs-test
744-
tags: [doctests]
745-
746737
# Enterprise auth tests
747738
- name: test-enterprise-auth-python3.9
748739
commands:

‎.evergreen/generated_configs/variants.yml

+7-46
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ buildvariants:
213213
PYTHON_BINARY: /opt/python/3.9/bin/python3
214214

215215
# Doctests tests
216-
- name: doctests-rhel8-python3.9
216+
- name: doctests-rhel8
217217
tasks:
218-
- name: .doctests
219-
display_name: Doctests RHEL8 Python3.9
218+
- name: .standard-linux .standalone-noauth-nossl
219+
display_name: Doctests RHEL8
220220
run_on:
221221
- rhel87-small
222222
expansions:
223-
PYTHON_BINARY: /opt/python/3.9/bin/python3
223+
TEST_NAME: doctest
224224

225225
# Encryption tests
226226
- name: encryption-rhel8-python3.9
@@ -609,51 +609,12 @@ buildvariants:
609609
PYTHON_BINARY: /opt/python/3.13/bin/python3
610610

611611
# No c ext tests
612-
- name: no-c-ext-rhel8-python3.9
613-
tasks:
614-
- name: .standalone .noauth .nossl !.sync_async
615-
display_name: No C Ext RHEL8 Python3.9
616-
run_on:
617-
- rhel87-small
618-
expansions:
619-
NO_EXT: "1"
620-
PYTHON_BINARY: /opt/python/3.9/bin/python3
621-
- name: no-c-ext-rhel8-python3.10
612+
- name: no-c-ext-rhel8
622613
tasks:
623-
- name: .replica_set .noauth .nossl !.sync_async
624-
display_name: No C Ext RHEL8 Python3.10
625-
run_on:
626-
- rhel87-small
627-
expansions:
628-
NO_EXT: "1"
629-
PYTHON_BINARY: /opt/python/3.10/bin/python3
630-
- name: no-c-ext-rhel8-python3.11
631-
tasks:
632-
- name: .sharded_cluster .noauth .nossl !.sync_async
633-
display_name: No C Ext RHEL8 Python3.11
634-
run_on:
635-
- rhel87-small
636-
expansions:
637-
NO_EXT: "1"
638-
PYTHON_BINARY: /opt/python/3.11/bin/python3
639-
- name: no-c-ext-rhel8-python3.12
640-
tasks:
641-
- name: .standalone .noauth .nossl !.sync_async
642-
display_name: No C Ext RHEL8 Python3.12
643-
run_on:
644-
- rhel87-small
645-
expansions:
646-
NO_EXT: "1"
647-
PYTHON_BINARY: /opt/python/3.12/bin/python3
648-
- name: no-c-ext-rhel8-python3.13
649-
tasks:
650-
- name: .replica_set .noauth .nossl !.sync_async
651-
display_name: No C Ext RHEL8 Python3.13
614+
- name: .standard-linux
615+
display_name: No C Ext RHEL8
652616
run_on:
653617
- rhel87-small
654-
expansions:
655-
NO_EXT: "1"
656-
PYTHON_BINARY: /opt/python/3.13/bin/python3
657618

658619
# No server tests
659620
- name: no-server

‎.evergreen/scripts/generate_config.py

+9-30
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,12 @@ def create_green_framework_variants():
357357

358358

359359
def create_no_c_ext_variants():
360-
variants = []
361360
host = DEFAULT_HOST
362-
for python, topology in zip_cycle(CPYTHONS, TOPOLOGIES):
363-
tasks = [f".{topology} .noauth .nossl !.sync_async"]
364-
expansions = dict()
365-
handle_c_ext(C_EXTS[0], expansions)
366-
display_name = get_variant_name("No C Ext", host, python=python)
367-
variant = create_variant(
368-
tasks, display_name, host=host, python=python, expansions=expansions
369-
)
370-
variants.append(variant)
371-
return variants
361+
tasks = [".standard-linux"]
362+
expansions = dict()
363+
handle_c_ext(C_EXTS[0], expansions)
364+
display_name = get_variant_name("No C Ext", host)
365+
return [create_variant(tasks, display_name, host=host)]
372366

373367

374368
def create_atlas_data_lake_variants():
@@ -469,13 +463,13 @@ def create_mockupdb_variants():
469463

470464
def create_doctests_variants():
471465
host = DEFAULT_HOST
472-
python = CPYTHONS[0]
466+
expansions = dict(TEST_NAME="doctest")
473467
return [
474468
create_variant(
475-
[".doctests"],
476-
get_variant_name("Doctests", host, python=python),
477-
python=python,
469+
[".standard-linux .standalone-noauth-nossl"],
470+
get_variant_name("Doctests", host),
478471
host=host,
472+
expansions=expansions,
479473
)
480474
]
481475

@@ -1013,14 +1007,6 @@ def create_mockupdb_tasks():
10131007
return [EvgTask(name=task_name, tags=tags, commands=[test_func])]
10141008

10151009

1016-
def create_doctest_tasks():
1017-
server_func = FunctionCall(func="run server")
1018-
test_func = FunctionCall(func="run just script", vars=dict(JUSTFILE_TARGET="docs-test"))
1019-
task_name = "test-doctests"
1020-
tags = ["doctests"]
1021-
return [EvgTask(name=task_name, tags=tags, commands=[server_func, test_func])]
1022-
1023-
10241010
def create_no_server_tasks():
10251011
test_func = FunctionCall(func="run tests")
10261012
task_name = "test-no-server"
@@ -1164,13 +1150,6 @@ def create_run_server_func():
11641150
return "run server", [sub_cmd, expansion_cmd]
11651151

11661152

1167-
def create_run_just_script_func():
1168-
includes = ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
1169-
args = [".evergreen/just.sh", "${JUSTFILE_TARGET}"]
1170-
cmd = get_subprocess_exec(include_expansions_in_env=includes, args=args)
1171-
return "run just script", [cmd]
1172-
1173-
11741153
def create_run_tests_func():
11751154
includes = [
11761155
"AUTH",

‎.evergreen/scripts/run_tests.py

+7
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ def run() -> None:
152152
test_kms_send_to_remote(SUB_TEST_NAME)
153153
return
154154

155+
# Handle doctests.
156+
if TEST_NAME == "doctest":
157+
from sphinx.cmd.build import main
158+
159+
result = main("-E -b doctest doc ./doc/_build/doctest".split())
160+
sys.exit(result)
161+
155162
# Send ecs tests to run remotely.
156163
if TEST_NAME == "auth_aws" and SUB_TEST_NAME == "ecs":
157164
run_command(f"{DRIVERS_TOOLS}/.evergreen/auth_aws/aws_setup.sh ecs")

‎.evergreen/scripts/setup_tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ def handle_test_env() -> None:
285285
write_env("GSSAPI_PORT", config["SASL_PORT"])
286286
write_env("GSSAPI_PRINCIPAL", config["PRINCIPAL"])
287287

288+
if test_name == "doctest":
289+
UV_ARGS.append("--extra docs")
290+
288291
if test_name == "load_balancer":
289292
SINGLE_MONGOS_LB_URI = os.environ.get(
290293
"SINGLE_MONGOS_LB_URI", "mongodb://127.0.0.1:8000/?loadBalanced=true"

‎.evergreen/scripts/utils.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@ class Distro:
5252
# Tests that require a sub test suite.
5353
SUB_TEST_REQUIRED = ["auth_aws", "auth_oidc", "kms", "mod_wsgi", "perf"]
5454

55-
EXTRA_TESTS = ["mod_wsgi", "aws_lambda"]
55+
EXTRA_TESTS = ["mod_wsgi", "aws_lambda", "doctest"]
5656

5757
# Tests that do not use run-orchestration directly.
58-
NO_RUN_ORCHESTRATION = ["auth_oidc", "atlas_connect", "data_lake", "mockupdb", "serverless", "ocsp"]
58+
NO_RUN_ORCHESTRATION = [
59+
"auth_oidc",
60+
"atlas_connect",
61+
"aws_lambda",
62+
"data_lake",
63+
"mockupdb",
64+
"serverless",
65+
"ocsp",
66+
]
5967

6068

6169
def get_test_options(
@@ -78,7 +86,7 @@ def get_test_options(
7886
else:
7987
parser.add_argument(
8088
"test_name",
81-
choices=set(TEST_SUITE_MAP) - set(NO_RUN_ORCHESTRATION),
89+
choices=set(list(TEST_SUITE_MAP) + EXTRA_TESTS) - set(NO_RUN_ORCHESTRATION),
8290
nargs="?",
8391
default="default",
8492
help="The optional name of the test suite to be run, which informs the server configuration.",

‎.github/workflows/test-python.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ jobs:
9999
- name: Install dependencies
100100
run: just install
101101
- name: Run tests
102-
run: just docs-test
102+
run: |
103+
just setup-tests doctest
104+
just run-tests
103105
104106
docs:
105107
name: Docs Checks

‎CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ Note: these tests can only be run from an Evergreen host.
294294
The doc tests require a running server.
295295

296296
- Run `just run-server`.
297-
- Run `just docs-test`.
297+
- Run `just setup-tests doctest`.
298+
- Run `just run-tests`.
298299

299300
### Free-threaded Python Tests
300301

‎doc/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
client = MongoClient()
106106
client.drop_database("doctest_test")
107107
db = client.doctest_test
108+
server_major_version = int(client.server_info()['version'].split()[-1][0])
108109
"""
109110

110111
# -- Options for HTML output ---------------------------------------------------

‎doc/examples/client_bulk.rst

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ summary of the types of operations performed in the bulk write, along with their
4646

4747
.. doctest::
4848
:options: +NORMALIZE_WHITESPACE
49+
:skipif: server_major_version < 8
4950

5051
>>> from pymongo import InsertOne, DeleteOne, UpdateOne
5152
>>> models = [
@@ -79,6 +80,7 @@ instance will also include detailed results about each successful operation perf
7980

8081
.. doctest::
8182
:options: +NORMALIZE_WHITESPACE
83+
:skipif: server_major_version < 8
8284

8385
>>> from pymongo import InsertOne, DeleteMany, ReplaceOne, UpdateMany
8486
>>> models = [
@@ -125,6 +127,7 @@ For example, a duplicate key error on the third operation below aborts the remai
125127

126128
.. doctest::
127129
:options: +NORMALIZE_WHITESPACE
130+
:skipif: server_major_version < 8
128131

129132
>>> from pymongo import InsertOne, DeleteOne
130133
>>> from pymongo.errors import ClientBulkWriteException
@@ -161,6 +164,7 @@ For example, the fourth and fifth write operations below get executed successful
161164

162165
.. doctest::
163166
:options: +NORMALIZE_WHITESPACE
167+
:skipif: server_major_version < 8
164168

165169
>>> from pymongo import InsertOne, DeleteOne
166170
>>> from pymongo.errors import ClientBulkWriteException

‎justfile

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ docs-serve:
2828
docs-linkcheck:
2929
{{docs_run}} sphinx-build -E -b linkcheck doc {{doc_build}}/linkcheck
3030

31-
[group('docs')]
32-
docs-test:
33-
{{docs_run}} --extra test sphinx-build -E -b doctest doc {{doc_build}}/doctest
34-
3531
[group('typing')]
3632
typing:
3733
just typing-mypy

0 commit comments

Comments
 (0)
Please sign in to comment.