Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
33 changes: 33 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
run:
shell: bash -eux {0}

permissions:
contents: read

jobs:

static:
Expand Down Expand Up @@ -163,6 +166,36 @@
run: |
just typing
integration_tests:
runs-on: ubuntu-latest
name: Integration Tests
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@557e51de59eb14aaaba2ed9621916900a91d50c6 # v5
with:
enable-cache: true
python-version: "3.9"
- name: Install just
run: uv tool install rust-just
- name: Install dependencies
run: |
just install
- id: setup-mongodb
uses: mongodb-labs/drivers-evergreen-tools@master
- name: Run tests
run: |
just integration-tests
- id: setup-mongodb-ssl
uses: mongodb-labs/drivers-evergreen-tools@master
with:
ssl: true
- name: Run tests
run: |
just integration-tests
make_sdist:
runs-on: ubuntu-latest
name: "Make an sdist"
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ a use the ticket number as the "reason" parameter to the decorator, e.g. `@flaky
When running tests locally (not in CI), the `flaky` decorator will be disabled unless `ENABLE_FLAKY` is set.
To disable the `flaky` decorator in CI, you can use `evergreen patch --param DISABLE_FLAKY=1`.

## Integration Tests

The `integration_tests` directory has a set of scripts that verify the usage of PyMongo with downstream packages or frameworks. See the [README](./integration_tests/README.md) for more information.

To run the tests, use `just integration_tests`.

The tests should be able to run with and without SSL enabled.

## Specification Tests

The MongoDB [specifications repository](https://github.com/mongodb/specifications)
Expand Down
42 changes: 42 additions & 0 deletions integration_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Integration Tests

A set of tests that verify the usage of PyMongo with downstream packages or frameworks.

Each test uses [PEP 723 inline metadata](https://packaging.python.org/en/latest/specifications/inline-script-metadata/) and can be run using `pipx` or `uv`.

The `run.sh` convenience script can be used to run all of the files using `uv`.

Here is an example header for the script with the inline dependencies:

```python
# /// script
# dependencies = [
# "uvloop>=0.18"
# ]
# requires-python = ">=3.10"
# ///
```

Here is an example of using the test helper function to create a configured client for the test:


```python
import asyncio
import sys
from pathlib import Path

# Use pymongo from parent directory.
root = Path(__file__).parent.parent
sys.path.insert(0, str(root))

from test.asynchronous import async_simple_test_client # noqa: E402


async def main():
async with async_simple_test_client() as client:
result = await client.admin.command("ping")
assert result["ok"]


asyncio.run(main())
```
11 changes: 11 additions & 0 deletions integration_tests/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# Run all of the integration test files using `uv run`.
set -eu

for file in integration_tests/test_*.py ; do
echo "-----------------"
echo "Running $file..."
uv run $file
echo "Running $file...done."
echo "-----------------"
done
27 changes: 27 additions & 0 deletions integration_tests/test_uv_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# /// script
# dependencies = [
# "uvloop>=0.18"
# ]
# requires-python = ">=3.10"
# ///
from __future__ import annotations

import sys
from pathlib import Path

import uvloop

# Use pymongo from parent directory.
root = Path(__file__).parent.parent
sys.path.insert(0, str(root))

from test.asynchronous import async_simple_test_client # noqa: E402


async def main():
async with async_simple_test_client() as client:
result = await client.admin.command("ping")
assert result["ok"]


uvloop.run(main())
6 changes: 4 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# See https://just.systems/man/en/ for instructions
set shell := ["bash", "-c"]
# Do not modify the lock file when running justfile commands.
export UV_FROZEN := "1"

# Commonly used command segments.
typing_run := "uv run --group typing --extra aws --extra encryption --extra ocsp --extra snappy --extra test --extra zstd"
Expand Down Expand Up @@ -73,6 +71,10 @@ setup-tests *args="":
teardown-tests:
bash .evergreen/scripts/teardown-tests.sh

[group('test')]
integration-tests:
bash integration_tests/run.sh

[group('server')]
run-server *args="":
bash .evergreen/scripts/run-server.sh {{args}}
Expand Down
7 changes: 7 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,13 @@ def teardown():
print_running_clients()


@contextmanager
def simple_test_client():
client_context.init()
yield client_context.client
client_context.client.close()


def test_cases(suite):
"""Iterator over all TestCases within a TestSuite."""
for suite_or_case in suite._tests:
Expand Down
7 changes: 7 additions & 0 deletions test/asynchronous/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,13 @@ async def async_teardown():
print_running_clients()


@asynccontextmanager
async def async_simple_test_client():
await async_client_context.init()
yield async_client_context.client
await async_client_context.client.close()


def test_cases(suite):
"""Iterator over all TestCases within a TestSuite."""
for suite_or_case in suite._tests:
Expand Down
1 change: 1 addition & 0 deletions tools/synchro.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"async_create_barrier": "create_barrier",
"async_barrier_wait": "barrier_wait",
"async_joinall": "joinall",
"async_simple_test_client": "simple_test_client",
"_async_create_connection": "_create_connection",
"pymongo.asynchronous.srv_resolver._SrvResolver.get_hosts": "pymongo.synchronous.srv_resolver._SrvResolver.get_hosts",
"dns.asyncresolver.resolve": "dns.resolver.resolve",
Expand Down
Loading