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:
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
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
419419
420420To 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
424426The 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/
66
77The ` 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
1425import sys
1526from pathlib import Path
1627
28+ # Use pymongo from parent directory.
1729root = Path(__file__ ).parent.parent
1830sys.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```
Original file line number Diff line number Diff line change 1515root = Path (__file__ ).parent .parent
1616sys .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
2121async 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
2727uvloop .run (main ())
Original file line number Diff line number Diff 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+
12511258def test_cases (suite ):
12521259 """Iterator over all TestCases within a TestSuite."""
12531260 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():
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+
12671274def test_cases (suite ):
12681275 """Iterator over all TestCases within a TestSuite."""
12691276 for suite_or_case in suite ._tests :
You can’t perform that action at this time.
0 commit comments