Skip to content

PYTHON-5220 Convert remaining tests to use standard test setup #2211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 9 additions & 47 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ functions:
# Make an evergreen expansion file with dynamic values
- command: subprocess.exec
params:
include_expansions_in_env: ["is_patch", "project", "version_id", "skip_web_identity_auth_test", "skip_ECS_auth_test"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are unused, and should have been removed when i refactored the aws tests.

include_expansions_in_env: ["is_patch", "project", "version_id"]
binary: bash
working_dir: "src"
args:
Expand Down Expand Up @@ -213,16 +213,14 @@ functions:
params:
file: ${DRIVERS_TOOLS}/mo-expansion.yml

"run doctests":
- command: subprocess.exec
type: test
params:
include_expansions_in_env: [ "PYTHON_BINARY" ]
working_dir: "src"
binary: bash
args:
- .evergreen/scripts/run-with-env.sh
- .evergreen/scripts/run-doctests.sh
"run just script":
- command: subprocess.exec
type: test
params:
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
binary: bash
working_dir: "src"
args: [.evergreen/just.sh, "${JUSTFILE_TARGET}"]

"run tests":
- command: subprocess.exec
Expand All @@ -248,7 +246,6 @@ functions:
binary: bash
working_dir: "src"
args:
- .evergreen/scripts/run-with-env.sh
- .evergreen/scripts/cleanup.sh

"teardown system":
Expand Down Expand Up @@ -305,36 +302,7 @@ tasks:
params:
args:
- src/.evergreen/scripts/run-getdata.sh
# Standard test tasks {{{

- name: "mockupdb"
tags: ["mockupdb"]
commands:
- func: "run tests"
vars:
TEST_NAME: mockupdb

- name: "doctests"
tags: ["doctests"]
commands:
- func: "run server"
- func: "run doctests"

- name: "no-server"
tags: ["no-server"]
commands:
- func: "run tests"

- name: "free-threading"
tags: ["free-threading"]
commands:
- func: "run server"
vars:
VERSION: "8.0"
TOPOLOGY: "replica_set"
- func: "run tests"

# }}}
- name: "coverage-report"
tags: ["coverage"]
depends_on:
Expand Down Expand Up @@ -384,12 +352,6 @@ tasks:
- ${github_commit}

buildvariants:
- name: "no-server"
display_name: "No server"
run_on:
- rhel84-small
tasks:
- name: "no-server"

- name: "Coverage Report"
display_name: "Coverage Report"
Expand Down
33 changes: 33 additions & 0 deletions .evergreen/generated_configs/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,15 @@ tasks:
AWS_ROLE_SESSION_NAME: test
tags: [auth-aws, auth-aws-web-identity]

# Doctest tests
- name: test-doctests
commands:
- func: run server
- func: run just script
vars:
JUSTFILE_TARGET: docs-test
tags: [doctests]

# Enterprise auth tests
- name: test-enterprise-auth
commands:
Expand All @@ -727,6 +736,16 @@ tasks:
AUTH: auth
tags: [enterprise_auth]

# Free threading tests
- name: test-free-threading
commands:
- func: run server
vars:
VERSION: "8.0"
TOPOLOGY: replica_set
- func: run tests
tags: [free-threading]

# Kms tests
- name: test-gcpkms
commands:
Expand Down Expand Up @@ -799,6 +818,14 @@ tasks:
TEST_NAME: load_balancer
tags: [load-balancer, noauth, nossl]

# Mockupdb tests
- name: test-mockupdb
commands:
- func: run tests
vars:
TEST_NAME: mockupdb
tags: [mockupdb]

# Mod wsgi tests
- name: mod-wsgi-standalone
commands:
Expand Down Expand Up @@ -841,6 +868,12 @@ tasks:
SUB_TEST_NAME: embedded
tags: [mod_wsgi]

# No server tests
- name: test-no-server
commands:
- func: run tests
tags: [no-server]

# Ocsp tests
- name: test-ocsp-ecdsa-valid-cert-server-does-not-staple
commands:
Expand Down
12 changes: 10 additions & 2 deletions .evergreen/generated_configs/variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ buildvariants:
# Doctests tests
- name: doctests-rhel8-python3.9
tasks:
- name: doctests
- name: .doctests
display_name: Doctests RHEL8 Python3.9
run_on:
- rhel87-small
Expand Down Expand Up @@ -672,7 +672,7 @@ buildvariants:
# Mockupdb tests
- name: mockupdb-rhel8-python3.9
tasks:
- name: mockupdb
- name: .mockupdb
display_name: MockupDB RHEL8 Python3.9
run_on:
- rhel87-small
Expand Down Expand Up @@ -746,6 +746,14 @@ buildvariants:
NO_EXT: "1"
PYTHON_BINARY: /opt/python/3.13/bin/python3

# No server tests
- name: no-server
tasks:
- name: .no-server
display_name: No server
run_on:
- rhel87-small

# Ocsp tests
- name: ocsp-rhel8-v4.4-python3.9
tasks:
Expand Down
5 changes: 4 additions & 1 deletion .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ fi
uv sync ${UV_ARGS} --reinstall
uv pip list

# Ensure we go back to base environment after the test.
trap "uv sync" EXIT HUP

# Start the test runner.
uv run .evergreen/scripts/run_tests.py "$@"
uv run ${UV_ARGS} .evergreen/scripts/run_tests.py "$@"

popd
8 changes: 8 additions & 0 deletions .evergreen/scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#!/bin/bash

HERE=$(dirname ${BASH_SOURCE:-$0})

# Try to source the env file.
if [ -f $HERE/env.sh ]; then
echo "Sourcing env file"
source $HERE/env.sh
fi

rm -rf "${DRIVERS_TOOLS}" || true
rm -f ./secrets-export.sh || true
2 changes: 0 additions & 2 deletions .evergreen/scripts/configure-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export MONGO_ORCHESTRATION_HOME="$MONGO_ORCHESTRATION_HOME"
export MONGODB_BINARIES="$MONGODB_BINARIES"
export DRIVERS_TOOLS_BINARIES="$DRIVERS_TOOLS_BINARIES"
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
export skip_web_identity_auth_test="${skip_web_identity_auth_test:-}"
export skip_ECS_auth_test="${skip_ECS_auth_test:-}"

export CARGO_HOME="$CARGO_HOME"
export UV_TOOL_DIR="$UV_TOOL_DIR"
Expand Down
40 changes: 38 additions & 2 deletions .evergreen/scripts/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def create_mockupdb_variants():
python = CPYTHONS[0]
return [
create_variant(
["mockupdb"],
[".mockupdb"],
get_display_name("MockupDB", host, python=python),
python=python,
host=host,
Expand All @@ -698,7 +698,7 @@ def create_doctests_variants():
python = CPYTHONS[0]
return [
create_variant(
["doctests"],
[".doctests"],
get_display_name("Doctests", host, python=python),
python=python,
host=host,
Expand Down Expand Up @@ -748,6 +748,11 @@ def create_aws_auth_variants():
return variants


def create_no_server_variants():
host = HOSTS["rhel8"]
return [create_variant([".no-server"], "No server", host=host)]


def create_alternative_hosts_variants():
batchtime = BATCHTIME_WEEK
variants = []
Expand Down Expand Up @@ -1040,6 +1045,37 @@ def create_ocsp_tasks():
return tasks


def create_mockupdb_tasks():
test_func = FunctionCall(func="run tests", vars=dict(TEST_NAME="mockupdb"))
task_name = "test-mockupdb"
tags = ["mockupdb"]
return [EvgTask(name=task_name, tags=tags, commands=[test_func])]


def create_doctest_tasks():
server_func = FunctionCall(func="run server")
test_func = FunctionCall(func="run just script", vars=dict(JUSTFILE_TARGET="docs-test"))
task_name = "test-doctests"
tags = ["doctests"]
return [EvgTask(name=task_name, tags=tags, commands=[server_func, test_func])]


def create_no_server_tasks():
test_func = FunctionCall(func="run tests")
task_name = "test-no-server"
tags = ["no-server"]
return [EvgTask(name=task_name, tags=tags, commands=[test_func])]


def create_free_threading_tasks():
vars = dict(VERSION="8.0", TOPOLOGY="replica_set")
server_func = FunctionCall(func="run server", vars=vars)
test_func = FunctionCall(func="run tests")
task_name = "test-free-threading"
tags = ["free-threading"]
return [EvgTask(name=task_name, tags=tags, commands=[server_func, test_func])]


def create_serverless_tasks():
vars = dict(TEST_NAME="serverless", AUTH="auth", SSL="ssl")
test_func = FunctionCall(func="run tests", vars=vars)
Expand Down
21 changes: 0 additions & 21 deletions .evergreen/scripts/run-with-env.sh

This file was deleted.

3 changes: 1 addition & 2 deletions .evergreen/scripts/setup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ def handle_test_env() -> None:
TEST_ARGS = ""

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

test_title = test_name
if sub_test_name:
Expand Down
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,27 @@ Note: these tests can only be run from an Evergreen host.
- Run `just setup-tests search_index`.
- Run `just run-tests`.

### MockupDB tests

- Run `just setup-tests mockupdb`.
- Run `just run-tests`.

### Doc tests

The doc tests require a running server.

- Run `just run-server`.
- Run `just docs-test`.

### Free-threaded Python Tests

In the evergreen builds, the tests are configured to use the free-threaded python from the toolchain.
Locally you can run:

- Run `just run-server`.
- Run `just setup-tests`.
- Run `UV_PYTHON=3.13t just run-tests`.

### AWS Lambda tests

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).
Expand Down
2 changes: 2 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading