|
14 | 14 |
|
15 | 15 | import os |
16 | 16 | import pathlib |
| 17 | +import re |
17 | 18 | import shutil |
18 | 19 |
|
19 | 20 | import nox |
@@ -226,3 +227,73 @@ def pypy(session): |
226 | 227 | "tests", |
227 | 228 | "tests_async", |
228 | 229 | ) |
| 230 | + |
| 231 | + |
| 232 | +@nox.session(python=DEFAULT_PYTHON_VERSION) |
| 233 | +@nox.parametrize( |
| 234 | + "protobuf_implementation", |
| 235 | + ["python", "upb", "cpp"], |
| 236 | +) |
| 237 | +def prerelease_deps(session, protobuf_implementation): |
| 238 | + """ |
| 239 | + Run all tests with pre-release versions of dependencies installed |
| 240 | + rather than the standard non pre-release versions. |
| 241 | + Pre-release versions can be installed using |
| 242 | + `pip install --pre <package>`. |
| 243 | + """ |
| 244 | + |
| 245 | + if protobuf_implementation == "cpp" and session.python in ( |
| 246 | + "3.11", |
| 247 | + "3.12", |
| 248 | + "3.13", |
| 249 | + "3.14", |
| 250 | + ): |
| 251 | + session.skip("cpp implementation is not supported in python 3.11+") |
| 252 | + |
| 253 | + # Install all dependencies |
| 254 | + session.install("-e", ".[testing]") |
| 255 | + |
| 256 | + # Because we test minimum dependency versions on the minimum Python |
| 257 | + # version, the first version we test with in the unit tests sessions has a |
| 258 | + # constraints file containing all dependencies and extras. |
| 259 | + with open( |
| 260 | + CURRENT_DIRECTORY |
| 261 | + / "testing" |
| 262 | + / f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt", |
| 263 | + encoding="utf-8", |
| 264 | + ) as constraints_file: |
| 265 | + constraints_text = constraints_file.read() |
| 266 | + |
| 267 | + # Ignore leading whitespace and comment lines. |
| 268 | + constraints_deps = [ |
| 269 | + match.group(1) |
| 270 | + for match in re.finditer( |
| 271 | + r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE |
| 272 | + ) |
| 273 | + ] |
| 274 | + |
| 275 | + # Install dependencies specified in `testing/constraints-X.txt`. |
| 276 | + session.install(*constraints_deps) |
| 277 | + |
| 278 | + # Note: If a dependency is added to the `prerel_deps` list, |
| 279 | + # the `core_dependencies_from_source` list in the `core_deps_from_source` |
| 280 | + # nox session should also be updated. |
| 281 | + prerel_deps = [ |
| 282 | + "cachetools", |
| 283 | + "pyasn1-modules", |
| 284 | + "cryptography", |
| 285 | + "requests", |
| 286 | + "aiohttp", |
| 287 | + ] |
| 288 | + |
| 289 | + for dep in prerel_deps: |
| 290 | + session.install("--pre", "--no-deps", "--ignore-installed", dep) |
| 291 | + |
| 292 | + session.run( |
| 293 | + "py.test", |
| 294 | + "tests/unit", |
| 295 | + env={ |
| 296 | + "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, |
| 297 | + }, |
| 298 | + ) |
| 299 | + |
0 commit comments