Skip to content

Commit 737a1b7

Browse files
authored
PYTHON-5220 Convert remaining tests to use standard test setup (#2211)
1 parent 134f52f commit 737a1b7

File tree

11 files changed

+126
-77
lines changed

11 files changed

+126
-77
lines changed

.evergreen/config.yml

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ functions:
4242
# Make an evergreen expansion file with dynamic values
4343
- command: subprocess.exec
4444
params:
45-
include_expansions_in_env: ["is_patch", "project", "version_id", "skip_web_identity_auth_test", "skip_ECS_auth_test"]
45+
include_expansions_in_env: ["is_patch", "project", "version_id"]
4646
binary: bash
4747
working_dir: "src"
4848
args:
@@ -213,16 +213,14 @@ functions:
213213
params:
214214
file: ${DRIVERS_TOOLS}/mo-expansion.yml
215215

216-
"run doctests":
217-
- command: subprocess.exec
218-
type: test
219-
params:
220-
include_expansions_in_env: [ "PYTHON_BINARY" ]
221-
working_dir: "src"
222-
binary: bash
223-
args:
224-
- .evergreen/scripts/run-with-env.sh
225-
- .evergreen/scripts/run-doctests.sh
216+
"run just script":
217+
- command: subprocess.exec
218+
type: test
219+
params:
220+
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
221+
binary: bash
222+
working_dir: "src"
223+
args: [.evergreen/just.sh, "${JUSTFILE_TARGET}"]
226224

227225
"run tests":
228226
- command: subprocess.exec
@@ -248,7 +246,6 @@ functions:
248246
binary: bash
249247
working_dir: "src"
250248
args:
251-
- .evergreen/scripts/run-with-env.sh
252249
- .evergreen/scripts/cleanup.sh
253250

254251
"teardown system":
@@ -305,36 +302,7 @@ tasks:
305302
params:
306303
args:
307304
- src/.evergreen/scripts/run-getdata.sh
308-
# Standard test tasks {{{
309-
310-
- name: "mockupdb"
311-
tags: ["mockupdb"]
312-
commands:
313-
- func: "run tests"
314-
vars:
315-
TEST_NAME: mockupdb
316-
317-
- name: "doctests"
318-
tags: ["doctests"]
319-
commands:
320-
- func: "run server"
321-
- func: "run doctests"
322305

323-
- name: "no-server"
324-
tags: ["no-server"]
325-
commands:
326-
- func: "run tests"
327-
328-
- name: "free-threading"
329-
tags: ["free-threading"]
330-
commands:
331-
- func: "run server"
332-
vars:
333-
VERSION: "8.0"
334-
TOPOLOGY: "replica_set"
335-
- func: "run tests"
336-
337-
# }}}
338306
- name: "coverage-report"
339307
tags: ["coverage"]
340308
depends_on:
@@ -384,12 +352,6 @@ tasks:
384352
- ${github_commit}
385353

386354
buildvariants:
387-
- name: "no-server"
388-
display_name: "No server"
389-
run_on:
390-
- rhel84-small
391-
tasks:
392-
- name: "no-server"
393355

394356
- name: "Coverage Report"
395357
display_name: "Coverage Report"

.evergreen/generated_configs/tasks.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,15 @@ tasks:
713713
AWS_ROLE_SESSION_NAME: test
714714
tags: [auth-aws, auth-aws-web-identity]
715715

716+
# Doctest tests
717+
- name: test-doctests
718+
commands:
719+
- func: run server
720+
- func: run just script
721+
vars:
722+
JUSTFILE_TARGET: docs-test
723+
tags: [doctests]
724+
716725
# Enterprise auth tests
717726
- name: test-enterprise-auth
718727
commands:
@@ -727,6 +736,16 @@ tasks:
727736
AUTH: auth
728737
tags: [enterprise_auth]
729738

739+
# Free threading tests
740+
- name: test-free-threading
741+
commands:
742+
- func: run server
743+
vars:
744+
VERSION: "8.0"
745+
TOPOLOGY: replica_set
746+
- func: run tests
747+
tags: [free-threading]
748+
730749
# Kms tests
731750
- name: test-gcpkms
732751
commands:
@@ -799,6 +818,14 @@ tasks:
799818
TEST_NAME: load_balancer
800819
tags: [load-balancer, noauth, nossl]
801820

821+
# Mockupdb tests
822+
- name: test-mockupdb
823+
commands:
824+
- func: run tests
825+
vars:
826+
TEST_NAME: mockupdb
827+
tags: [mockupdb]
828+
802829
# Mod wsgi tests
803830
- name: mod-wsgi-standalone
804831
commands:
@@ -841,6 +868,12 @@ tasks:
841868
SUB_TEST_NAME: embedded
842869
tags: [mod_wsgi]
843870

871+
# No server tests
872+
- name: test-no-server
873+
commands:
874+
- func: run tests
875+
tags: [no-server]
876+
844877
# Ocsp tests
845878
- name: test-ocsp-ecdsa-valid-cert-server-does-not-staple
846879
commands:

.evergreen/generated_configs/variants.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ buildvariants:
242242
# Doctests tests
243243
- name: doctests-rhel8-python3.9
244244
tasks:
245-
- name: doctests
245+
- name: .doctests
246246
display_name: Doctests RHEL8 Python3.9
247247
run_on:
248248
- rhel87-small
@@ -672,7 +672,7 @@ buildvariants:
672672
# Mockupdb tests
673673
- name: mockupdb-rhel8-python3.9
674674
tasks:
675-
- name: mockupdb
675+
- name: .mockupdb
676676
display_name: MockupDB RHEL8 Python3.9
677677
run_on:
678678
- rhel87-small
@@ -746,6 +746,14 @@ buildvariants:
746746
NO_EXT: "1"
747747
PYTHON_BINARY: /opt/python/3.13/bin/python3
748748

749+
# No server tests
750+
- name: no-server
751+
tasks:
752+
- name: .no-server
753+
display_name: No server
754+
run_on:
755+
- rhel87-small
756+
749757
# Ocsp tests
750758
- name: ocsp-rhel8-v4.4-python3.9
751759
tasks:

.evergreen/run-tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ fi
3434
uv sync ${UV_ARGS} --reinstall
3535
uv pip list
3636

37+
# Ensure we go back to base environment after the test.
38+
trap "uv sync" EXIT HUP
39+
3740
# Start the test runner.
38-
uv run .evergreen/scripts/run_tests.py "$@"
41+
uv run ${UV_ARGS} .evergreen/scripts/run_tests.py "$@"
3942

4043
popd

.evergreen/scripts/cleanup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/bash
22

3+
HERE=$(dirname ${BASH_SOURCE:-$0})
4+
5+
# Try to source the env file.
6+
if [ -f $HERE/env.sh ]; then
7+
echo "Sourcing env file"
8+
source $HERE/env.sh
9+
fi
10+
311
rm -rf "${DRIVERS_TOOLS}" || true
412
rm -f ./secrets-export.sh || true

.evergreen/scripts/configure-env.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ export MONGO_ORCHESTRATION_HOME="$MONGO_ORCHESTRATION_HOME"
6060
export MONGODB_BINARIES="$MONGODB_BINARIES"
6161
export DRIVERS_TOOLS_BINARIES="$DRIVERS_TOOLS_BINARIES"
6262
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
63-
export skip_web_identity_auth_test="${skip_web_identity_auth_test:-}"
64-
export skip_ECS_auth_test="${skip_ECS_auth_test:-}"
6563
6664
export CARGO_HOME="$CARGO_HOME"
6765
export UV_TOOL_DIR="$UV_TOOL_DIR"

.evergreen/scripts/generate_config.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def create_mockupdb_variants():
685685
python = CPYTHONS[0]
686686
return [
687687
create_variant(
688-
["mockupdb"],
688+
[".mockupdb"],
689689
get_display_name("MockupDB", host, python=python),
690690
python=python,
691691
host=host,
@@ -698,7 +698,7 @@ def create_doctests_variants():
698698
python = CPYTHONS[0]
699699
return [
700700
create_variant(
701-
["doctests"],
701+
[".doctests"],
702702
get_display_name("Doctests", host, python=python),
703703
python=python,
704704
host=host,
@@ -748,6 +748,11 @@ def create_aws_auth_variants():
748748
return variants
749749

750750

751+
def create_no_server_variants():
752+
host = HOSTS["rhel8"]
753+
return [create_variant([".no-server"], "No server", host=host)]
754+
755+
751756
def create_alternative_hosts_variants():
752757
batchtime = BATCHTIME_WEEK
753758
variants = []
@@ -1040,6 +1045,37 @@ def create_ocsp_tasks():
10401045
return tasks
10411046

10421047

1048+
def create_mockupdb_tasks():
1049+
test_func = FunctionCall(func="run tests", vars=dict(TEST_NAME="mockupdb"))
1050+
task_name = "test-mockupdb"
1051+
tags = ["mockupdb"]
1052+
return [EvgTask(name=task_name, tags=tags, commands=[test_func])]
1053+
1054+
1055+
def create_doctest_tasks():
1056+
server_func = FunctionCall(func="run server")
1057+
test_func = FunctionCall(func="run just script", vars=dict(JUSTFILE_TARGET="docs-test"))
1058+
task_name = "test-doctests"
1059+
tags = ["doctests"]
1060+
return [EvgTask(name=task_name, tags=tags, commands=[server_func, test_func])]
1061+
1062+
1063+
def create_no_server_tasks():
1064+
test_func = FunctionCall(func="run tests")
1065+
task_name = "test-no-server"
1066+
tags = ["no-server"]
1067+
return [EvgTask(name=task_name, tags=tags, commands=[test_func])]
1068+
1069+
1070+
def create_free_threading_tasks():
1071+
vars = dict(VERSION="8.0", TOPOLOGY="replica_set")
1072+
server_func = FunctionCall(func="run server", vars=vars)
1073+
test_func = FunctionCall(func="run tests")
1074+
task_name = "test-free-threading"
1075+
tags = ["free-threading"]
1076+
return [EvgTask(name=task_name, tags=tags, commands=[server_func, test_func])]
1077+
1078+
10431079
def create_serverless_tasks():
10441080
vars = dict(TEST_NAME="serverless", AUTH="auth", SSL="ssl")
10451081
test_func = FunctionCall(func="run tests", vars=vars)

.evergreen/scripts/run-with-env.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

.evergreen/scripts/setup_tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ def handle_test_env() -> None:
128128
TEST_ARGS = ""
129129

130130
# Start compiling the args we'll pass to uv.
131-
# Run in an isolated environment so as not to pollute the base venv.
132-
UV_ARGS = ["--isolated --extra test"]
131+
UV_ARGS = ["--extra test --no-group dev"]
133132

134133
test_title = test_name
135134
if sub_test_name:

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,27 @@ Note: these tests can only be run from an Evergreen host.
282282
- Run `just setup-tests search_index`.
283283
- Run `just run-tests`.
284284

285+
### MockupDB tests
286+
287+
- Run `just setup-tests mockupdb`.
288+
- Run `just run-tests`.
289+
290+
### Doc tests
291+
292+
The doc tests require a running server.
293+
294+
- Run `just run-server`.
295+
- Run `just docs-test`.
296+
297+
### Free-threaded Python Tests
298+
299+
In the evergreen builds, the tests are configured to use the free-threaded python from the toolchain.
300+
Locally you can run:
301+
302+
- Run `just run-server`.
303+
- Run `just setup-tests`.
304+
- Run `UV_PYTHON=3.13t just run-tests`.
305+
285306
### AWS Lambda tests
286307

287308
You will need to set up access to the `drivers-test-secrets-role`, see the [Wiki](https://wiki.corp.mongodb.com/spaces/DRIVERS/pages/239737385/Using+AWS+Secrets+Manager+to+Store+Testing+Secrets).

0 commit comments

Comments
 (0)