File tree Expand file tree Collapse file tree 6 files changed +54
-11
lines changed Expand file tree Collapse file tree 6 files changed +54
-11
lines changed Original file line number Diff line number Diff line change @@ -180,15 +180,19 @@ jobs:
180
180
python-version : " 3.9"
181
181
- name : Install just
182
182
run : uv tool install rust-just
183
- - id : setup-mongodb
184
- uses : mongodb-labs/drivers-evergreen-tools@master
185
- with :
186
- version : " 8.0"
187
183
- name : Install dependencies
188
- run : just install
184
+ run : |
185
+ just install
186
+ - name : Start server
187
+ run : just run-server
189
188
- name : Run tests
190
189
run : |
191
190
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
192
196
193
197
make_sdist :
194
198
runs-on : ubuntu-latest
Original file line number Diff line number Diff line change @@ -419,6 +419,8 @@ The `integration_tests` directory has a set of scripts that verify the usage of
419
419
420
420
To run the tests, use ` just integration_tests ` .
421
421
422
+ The tests should be able to run with and without SSL enabled.
423
+
422
424
## Specification Tests
423
425
424
426
The MongoDB [ specifications repository] ( https://github.com/mongodb/specifications )
Original file line number Diff line number Diff line change @@ -6,14 +6,37 @@ Each test uses [PEP 723 inline metadata](https://packaging.python.org/en/latest/
6
6
7
7
The ` run.sh ` convenience script can be used to run all of the files using ` uv ` .
8
8
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:
10
21
11
22
12
23
``` python
13
- # Use pymongo from parent directory.
24
+ import asyncio
14
25
import sys
15
26
from pathlib import Path
16
27
28
+ # Use pymongo from parent directory.
17
29
root = Path(__file__ ).parent.parent
18
30
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())
19
42
```
Original file line number Diff line number Diff line change 15
15
root = Path (__file__ ).parent .parent
16
16
sys .path .insert (0 , str (root ))
17
17
18
- from pymongo import AsyncMongoClient # noqa: E402
18
+ from test . asynchronous import async_simple_test_client # noqa: E402
19
19
20
20
21
21
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" ]
25
25
26
26
27
27
uvloop .run (main ())
Original file line number Diff line number Diff line change @@ -1248,6 +1248,13 @@ def teardown():
1248
1248
print_running_clients ()
1249
1249
1250
1250
1251
+ @contextmanager
1252
+ def async_simple_test_client ():
1253
+ client_context .init ()
1254
+ yield client_context .client
1255
+ client_context .client .close ()
1256
+
1257
+
1251
1258
def test_cases (suite ):
1252
1259
"""Iterator over all TestCases within a TestSuite."""
1253
1260
for suite_or_case in suite ._tests :
Original file line number Diff line number Diff line change @@ -1264,6 +1264,13 @@ async def async_teardown():
1264
1264
print_running_clients ()
1265
1265
1266
1266
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
+
1267
1274
def test_cases (suite ):
1268
1275
"""Iterator over all TestCases within a TestSuite."""
1269
1276
for suite_or_case in suite ._tests :
You can’t perform that action at this time.
0 commit comments