Skip to content

Commit d6c6a15

Browse files
committed
Support running ssl-enabled integration tests
1 parent 38a4fb6 commit d6c6a15

File tree

6 files changed

+54
-11
lines changed

6 files changed

+54
-11
lines changed

.github/workflows/test-python.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,19 @@ jobs:
180180
python-version: "3.9"
181181
- name: Install just
182182
run: uv tool install rust-just
183-
- id: setup-mongodb
184-
uses: mongodb-labs/drivers-evergreen-tools@master
185-
with:
186-
version: "8.0"
187183
- name: Install dependencies
188-
run: just install
184+
run: |
185+
just install
186+
- name: Start server
187+
run: just run-server
189188
- name: Run tests
190189
run: |
191190
just integration-tests
191+
- name: Start server with SSL
192+
run: just run-server --ssl
193+
- name: Run tests
194+
run: |
195+
SSL=ssl just integration-tests
192196
193197
make_sdist:
194198
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ The `integration_tests` directory has a set of scripts that verify the usage of
419419

420420
To run the tests, use `just integration_tests`.
421421

422+
The tests should be able to run with and without SSL enabled.
423+
422424
## Specification Tests
423425

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

integration_tests/README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,37 @@ Each test uses [PEP 723 inline metadata](https://packaging.python.org/en/latest/
66

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

9-
When creating a new script, use the following snippet to ensure that the local version of PyMongo is used:
9+
Here is an example header for the script with the inline dependencies:
10+
11+
```python
12+
# /// script
13+
# dependencies = [
14+
# "uvloop>=0.18"
15+
# ]
16+
# requires-python = ">=3.10"
17+
# ///
18+
```
19+
20+
Here is an example of using the test helper function to create a configured client for the test:
1021

1122

1223
```python
13-
# Use pymongo from parent directory.
24+
import asyncio
1425
import sys
1526
from pathlib import Path
1627

28+
# Use pymongo from parent directory.
1729
root = Path(__file__).parent.parent
1830
sys.path.insert(0, str(root))
31+
32+
from test.asynchronous import async_simple_test_client # noqa: E402
33+
34+
35+
async def main():
36+
async with async_simple_test_client() as client:
37+
result = await client.admin.command("ping")
38+
assert result["ok"]
39+
40+
41+
asyncio.run(main())
1942
```

integration_tests/test_uv_loop.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
root = Path(__file__).parent.parent
1616
sys.path.insert(0, str(root))
1717

18-
from pymongo import AsyncMongoClient # noqa: E402
18+
from test.asynchronous import async_simple_test_client # noqa: E402
1919

2020

2121
async def main():
22-
client = AsyncMongoClient()
23-
result = await client.admin.command("ping")
24-
assert result["ok"]
22+
async with async_simple_test_client() as client:
23+
result = await client.admin.command("ping")
24+
assert result["ok"]
2525

2626

2727
uvloop.run(main())

test/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,13 @@ def teardown():
12481248
print_running_clients()
12491249

12501250

1251+
@contextmanager
1252+
def async_simple_test_client():
1253+
client_context.init()
1254+
yield client_context.client
1255+
client_context.client.close()
1256+
1257+
12511258
def test_cases(suite):
12521259
"""Iterator over all TestCases within a TestSuite."""
12531260
for suite_or_case in suite._tests:

test/asynchronous/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,13 @@ async def async_teardown():
12641264
print_running_clients()
12651265

12661266

1267+
@asynccontextmanager
1268+
async def async_simple_test_client():
1269+
await async_client_context.init()
1270+
yield async_client_context.client
1271+
await async_client_context.client.close()
1272+
1273+
12671274
def test_cases(suite):
12681275
"""Iterator over all TestCases within a TestSuite."""
12691276
for suite_or_case in suite._tests:

0 commit comments

Comments
 (0)