Skip to content

Commit 4ce19a1

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver
2 parents 9e113e7 + 215b3b1 commit 4ce19a1

File tree

12 files changed

+144
-24
lines changed

12 files changed

+144
-24
lines changed

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@192325c86100d080feab897ff886c34abd4c83a3 # v3
49+
uses: github/codeql-action/init@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3
5050
with:
5151
languages: ${{ matrix.language }}
5252
build-mode: ${{ matrix.build-mode }}
@@ -63,6 +63,6 @@ jobs:
6363
pip install -e .
6464
6565
- name: Perform CodeQL Analysis
66-
uses: github/codeql-action/analyze@192325c86100d080feab897ff886c34abd4c83a3 # v3
66+
uses: github/codeql-action/analyze@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3
6767
with:
6868
category: "/language:${{matrix.language}}"

.github/workflows/test-python.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ defaults:
1414
run:
1515
shell: bash -eux {0}
1616

17+
permissions:
18+
contents: read
19+
1720
jobs:
1821

1922
static:
@@ -163,6 +166,36 @@ jobs:
163166
run: |
164167
just typing
165168
169+
integration_tests:
170+
runs-on: ubuntu-latest
171+
name: Integration Tests
172+
steps:
173+
- uses: actions/checkout@v5
174+
with:
175+
persist-credentials: false
176+
- name: Install uv
177+
uses: astral-sh/setup-uv@557e51de59eb14aaaba2ed9621916900a91d50c6 # v5
178+
with:
179+
enable-cache: true
180+
python-version: "3.10"
181+
- name: Install just
182+
run: uv tool install rust-just
183+
- name: Install dependencies
184+
run: |
185+
just install
186+
- id: setup-mongodb
187+
uses: mongodb-labs/drivers-evergreen-tools@master
188+
- name: Run tests
189+
run: |
190+
just integration-tests
191+
- id: setup-mongodb-ssl
192+
uses: mongodb-labs/drivers-evergreen-tools@master
193+
with:
194+
ssl: true
195+
- name: Run tests
196+
run: |
197+
just integration-tests
198+
166199
make_sdist:
167200
runs-on: ubuntu-latest
168201
name: "Make an sdist"

CONTRIBUTING.md

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

414+
## Integration Tests
415+
416+
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.
417+
418+
To run the tests, use `just integration_tests`.
419+
420+
The tests should be able to run with and without SSL enabled.
421+
414422
## Specification Tests
415423

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

integration_tests/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
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:
21+
22+
23+
```python
24+
import asyncio
25+
import sys
26+
from pathlib import Path
27+
28+
# Use pymongo from parent directory.
29+
root = Path(__file__).parent.parent
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())
42+
```

integration_tests/run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Run all of the integration test files using `uv run`.
3+
set -eu
4+
5+
for file in integration_tests/test_*.py ; do
6+
echo "-----------------"
7+
echo "Running $file..."
8+
uv run $file
9+
echo "Running $file...done."
10+
echo "-----------------"
11+
done

integration_tests/test_uv_loop.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# /// script
2+
# dependencies = [
3+
# "uvloop>=0.18"
4+
# ]
5+
# requires-python = ">=3.10"
6+
# ///
7+
from __future__ import annotations
8+
9+
import sys
10+
from pathlib import Path
11+
12+
import uvloop
13+
14+
# Use pymongo from parent directory.
15+
root = Path(__file__).parent.parent
16+
sys.path.insert(0, str(root))
17+
18+
from test.asynchronous import async_simple_test_client # noqa: E402
19+
20+
21+
async def main():
22+
async with async_simple_test_client() as client:
23+
result = await client.admin.command("ping")
24+
assert result["ok"]
25+
26+
27+
uvloop.run(main())

justfile

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

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

pymongo/asynchronous/srv_resolver.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import random
2020
from typing import TYPE_CHECKING, Any, Optional, Union
2121

22-
from pymongo.common import CONNECT_TIMEOUT, check_for_min_version
22+
from pymongo.common import CONNECT_TIMEOUT
2323
from pymongo.errors import ConfigurationError
2424

2525
if TYPE_CHECKING:
@@ -32,14 +32,6 @@ def _have_dnspython() -> bool:
3232
try:
3333
import dns # noqa: F401
3434

35-
dns_version, required_version, is_valid = check_for_min_version("dnspython")
36-
if not is_valid:
37-
raise RuntimeError(
38-
f"pymongo requires dnspython>={required_version}, "
39-
f"found version {dns_version}. "
40-
"Install a compatible version with pip"
41-
)
42-
4335
return True
4436
except ImportError:
4537
return False
@@ -79,8 +71,6 @@ def __init__(
7971
srv_service_name: str,
8072
srv_max_hosts: int = 0,
8173
):
82-
# Ensure the version of dnspython is compatible.
83-
_have_dnspython()
8474
self.__fqdn = fqdn
8575
self.__srv = srv_service_name
8676
self.__connect_timeout = connect_timeout or CONNECT_TIMEOUT

pymongo/synchronous/srv_resolver.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import random
2020
from typing import TYPE_CHECKING, Any, Optional, Union
2121

22-
from pymongo.common import CONNECT_TIMEOUT, check_for_min_version
22+
from pymongo.common import CONNECT_TIMEOUT
2323
from pymongo.errors import ConfigurationError
2424

2525
if TYPE_CHECKING:
@@ -32,14 +32,6 @@ def _have_dnspython() -> bool:
3232
try:
3333
import dns # noqa: F401
3434

35-
dns_version, required_version, is_valid = check_for_min_version("dnspython")
36-
if not is_valid:
37-
raise RuntimeError(
38-
f"pymongo requires dnspython>={required_version}, "
39-
f"found version {dns_version}. "
40-
"Install a compatible version with pip"
41-
)
42-
4335
return True
4436
except ImportError:
4537
return False
@@ -79,8 +71,6 @@ def __init__(
7971
srv_service_name: str,
8072
srv_max_hosts: int = 0,
8173
):
82-
# Ensure the version of dnspython is compatible.
83-
_have_dnspython()
8474
self.__fqdn = fqdn
8575
self.__srv = srv_service_name
8676
self.__connect_timeout = connect_timeout or CONNECT_TIMEOUT

test/__init__.py

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

12291229

1230+
@contextmanager
1231+
def simple_test_client():
1232+
client_context.init()
1233+
yield client_context.client
1234+
client_context.client.close()
1235+
1236+
12301237
def test_cases(suite):
12311238
"""Iterator over all TestCases within a TestSuite."""
12321239
for suite_or_case in suite._tests:

0 commit comments

Comments
 (0)