Skip to content

Commit 7f8006a

Browse files
committed
PYTHON-5550 Add a test that uses uvloop as the event loop
1 parent 359aca7 commit 7f8006a

File tree

6 files changed

+73
-2
lines changed

6 files changed

+73
-2
lines changed

.github/workflows/test-python.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,30 @@ jobs:
165165
run: |
166166
just typing
167167
168+
integration_tets:
169+
runs-on: ubuntu-latest
170+
name: Integration Tests
171+
steps:
172+
- uses: actions/checkout@v5
173+
with:
174+
persist-credentials: false
175+
- name: Install uv
176+
uses: astral-sh/setup-uv@557e51de59eb14aaaba2ed9621916900a91d50c6 # v5
177+
with:
178+
enable-cache: true
179+
python-version: "3.9"
180+
- name: Install just
181+
run: uv tool install rust-just
182+
- id: setup-mongodb
183+
uses: mongodb-labs/drivers-evergreen-tools@master
184+
with:
185+
version: "8.0"
186+
- name: Install dependencies
187+
run: just install
188+
- name: Run tests
189+
run: |
190+
just integration-tests
191+
168192
make_sdist:
169193
runs-on: ubuntu-latest
170194
name: "Make an sdist"

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ a use the ticket number as the "reason" parameter to the decorator, e.g. `@flaky
413413
When running tests locally (not in CI), the `flaky` decorator will be disabled unless `ENABLE_FLAKY` is set.
414414
To disable the `flaky` decorator in CI, you can use `evergreen patch --param DISABLE_FLAKY=1`.
415415

416+
## Integration Tests
417+
418+
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.
419+
420+
To run the tests, use `just integration_tests`.
421+
416422
## Specification Tests
417423

418424
The MongoDB [specifications repository](https://github.com/mongodb/specifications)

integration_tests/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Integration Tests
2+
3+
A set of tests that verify the usage of PyMongo with downstream packages or frameworks.
4+
5+
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`.
6+
7+
The `run.sh` convenience script can be used to run all of the files using `uv`.
8+
9+
When creating a new script, use the following snippet to ensure that the local version of PyMongo is used:
10+
11+
12+
```python
13+
# Use pymongo from parent directory.
14+
import sys
15+
from pathlib import Path
16+
17+
root = Path(__file__).parent.parent
18+
sys.path.insert(0, str(root))
19+
```

integration_tests/run.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# Run all of the integration test files using `uv run`.
3+
set -eu
4+
5+
HERE=$(dirname ${BASH_SOURCE:-$0})
6+
pushd "$HERE" > /dev/null
7+
trap 'popd' ERR
8+
9+
for file in test_*.py ; do
10+
echo "-----------------"
11+
echo "Running $file..."
12+
uv run $file
13+
echo "Running $file...done."
14+
echo "-----------------"
15+
done
16+
17+
popd

tools/test_uv_loop.py renamed to integration_tests/test_uv_loop.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# dependencies = [
33
# "uvloop>=0.18"
44
# ]
5-
# requires-python = ">=3.11"
5+
# requires-python = ">=3.10"
66
# ///
77
from __future__ import annotations
88

@@ -20,7 +20,8 @@
2020

2121
async def main():
2222
client = AsyncMongoClient()
23-
print(await client.admin.command("ping"))
23+
result = await client.admin.command("ping")
24+
assert result["ok"]
2425

2526

2627
uvloop.run(main())

justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ setup-tests *args="":
7373
teardown-tests:
7474
bash .evergreen/scripts/teardown-tests.sh
7575

76+
[group('test')]
77+
integration-tests:
78+
UV_FROZEN="0" bash integration_tests/run.sh
79+
7680
[group('server')]
7781
run-server *args="":
7882
bash .evergreen/scripts/run-server.sh {{args}}

0 commit comments

Comments
 (0)