diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef26a0b2bb..5e2e758ecd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -223,6 +223,7 @@ jobs: env: LSP: '${{ matrix.lsp }}' LSP_EXTRACT_FILE: '${{ matrix.lsp_extract_file }}' + SKIP_SSL_INSTALLATION: "${{ matrix.arch == 'x86' && 1 || 0 }}" - if: always() uses: codecov/codecov-action@v7 with: diff --git a/ci.sh b/ci.sh index 9362dbc727..d8d1094699 100755 --- a/ci.sh +++ b/ci.sh @@ -54,8 +54,13 @@ if [ "${NO_TEST_REQUIREMENTS-0}" == 1 ]; then python -m uv pip install pytest coverage -c test-requirements.txt flags="--skip-optional-imports" else - python -m uv pip install -r test-requirements.txt --no-deps flags="" + if [ "${SKIP_SSL_INSTALLATION-0}" == 1 ]; then + echo cryptography >excluded_deps + PIP_ARGS="--exclude excluded_deps" + flags="--skip-ssl-imports" + fi + python -m uv pip install -r test-requirements.txt --no-deps $PIP_ARGS fi # If we're testing with a LSP installed, then it might break network diff --git a/src/trio/_tests/pytest_plugin.py b/src/trio/_tests/pytest_plugin.py index bbb5093be5..b929ae3a73 100644 --- a/src/trio/_tests/pytest_plugin.py +++ b/src/trio/_tests/pytest_plugin.py @@ -9,6 +9,7 @@ RUN_SLOW = True SKIP_OPTIONAL_IMPORTS = False +SKIP_SSL_IMPORTS = False def pytest_addoption(parser: pytest.Parser) -> None: @@ -18,13 +19,18 @@ def pytest_addoption(parser: pytest.Parser) -> None: action="store_true", help="skip tests that rely on libraries not required by trio itself", ) + parser.addoption( + "--skip-ssl-imports", + action="store_true", + help="skip tests that rely on cryptography", + ) def pytest_configure(config: pytest.Config) -> None: - global RUN_SLOW + global RUN_SLOW, SKIP_OPTIONAL_IMPORTS, SKIP_SSL_IMPORTS RUN_SLOW = config.getoption("--run-slow", default=True) - global SKIP_OPTIONAL_IMPORTS SKIP_OPTIONAL_IMPORTS = config.getoption("--skip-optional-imports", default=False) + SKIP_SSL_IMPORTS = config.getoption("--skip-ssl-imports", default=False) @pytest.fixture @@ -47,8 +53,8 @@ def pytest_pyfunc_call(pyfuncitem: pytest.Function) -> None: pyfuncitem.obj = trio_test(pyfuncitem.obj) -def skip_if_optional_else_raise(error: ImportError) -> NoReturn: - if SKIP_OPTIONAL_IMPORTS: +def maybe_ignore_import_error(error: ImportError) -> NoReturn: + if SKIP_OPTIONAL_IMPORTS or (SKIP_SSL_IMPORTS and error.name == "cryptography"): pytest.skip(error.msg, allow_module_level=True) else: # pragma: no cover raise error diff --git a/src/trio/_tests/test_dtls.py b/src/trio/_tests/test_dtls.py index 99cb68f11f..5a34d8c811 100644 --- a/src/trio/_tests/test_dtls.py +++ b/src/trio/_tests/test_dtls.py @@ -8,13 +8,13 @@ import attrs import pytest -from trio._tests.pytest_plugin import skip_if_optional_else_raise +from trio._tests.pytest_plugin import maybe_ignore_import_error try: import trustme from OpenSSL import SSL except ImportError as error: - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) import trio diff --git a/src/trio/_tests/test_exports.py b/src/trio/_tests/test_exports.py index 1c2b46ca47..9a1f8451f4 100644 --- a/src/trio/_tests/test_exports.py +++ b/src/trio/_tests/test_exports.py @@ -19,7 +19,7 @@ import trio import trio.testing -from trio._tests.pytest_plugin import RUN_SLOW, skip_if_optional_else_raise +from trio._tests.pytest_plugin import RUN_SLOW, maybe_ignore_import_error from .. import _core, _util from .._core._tests.tutil import slow @@ -41,7 +41,7 @@ def _ensure_mypy_cache_updated() -> None: try: from mypy.api import run except ImportError as error: - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) global mypy_cache_updated if not mypy_cache_updated: @@ -159,7 +159,7 @@ def no_underscores(symbols: Iterable[str]) -> set[str]: try: from pylint.lint import PyLinter except ImportError as error: - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) linter = PyLinter() assert module.__file__ is not None @@ -172,7 +172,7 @@ def no_underscores(symbols: Iterable[str]) -> set[str]: try: import jedi except ImportError as error: - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) # Simulate typing "import trio; trio." script = jedi.Script(f"import {modname}; {modname}.") @@ -215,7 +215,7 @@ def no_underscores(symbols: Iterable[str]) -> set[str]: try: import pyright # noqa: F401 except ImportError as error: - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) import subprocess res = subprocess.run( @@ -380,7 +380,7 @@ def lookup_symbol(symbol: str) -> dict[str, Any]: # type: ignore[misc, explicit try: import jedi except ImportError as error: - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) script = jedi.Script( f"from {module_name} import {class_name}; {class_name}.", diff --git a/src/trio/_tests/test_ssl.py b/src/trio/_tests/test_ssl.py index 8eb0659270..f0dd884c64 100644 --- a/src/trio/_tests/test_ssl.py +++ b/src/trio/_tests/test_ssl.py @@ -13,7 +13,7 @@ import pytest from trio import StapledStream -from trio._tests.pytest_plugin import skip_if_optional_else_raise +from trio._tests.pytest_plugin import maybe_ignore_import_error from trio.abc import ReceiveStream, SendStream from trio.testing import MemoryReceiveStream, MemorySendStream @@ -21,7 +21,7 @@ import trustme from OpenSSL import SSL except ImportError as error: - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) import trio diff --git a/src/trio/_tests/tools/test_gen_exports.py b/src/trio/_tests/tools/test_gen_exports.py index 81e6d5f18f..3b923ed83d 100644 --- a/src/trio/_tests/tools/test_gen_exports.py +++ b/src/trio/_tests/tools/test_gen_exports.py @@ -4,14 +4,14 @@ import pytest -from trio._tests.pytest_plugin import skip_if_optional_else_raise +from trio._tests.pytest_plugin import maybe_ignore_import_error # imports in gen_exports that are not in `install_requires` in setup.py try: import astor # noqa: F401 import isort # noqa: F401 except ImportError as error: - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) from trio._tools.gen_exports import ( @@ -103,7 +103,7 @@ def test_process( import black # noqa: F401 # there's no dedicated CI run that has astor+isort, but lacks black. except ImportError as error: # pragma: no cover - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) modpath = tmp_path / "_module.py" genpath = tmp_path / "_generated_module.py" @@ -141,7 +141,7 @@ def test_run_ruff(tmp_path: Path) -> None: try: import ruff # noqa: F401 except ImportError as error: # pragma: no cover - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) file = File(tmp_path / "module.py", "module") @@ -168,7 +168,7 @@ def test_lint_failure(tmp_path: Path) -> None: import black # noqa: F401 import ruff # noqa: F401 except ImportError as error: # pragma: no cover - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) file = File(tmp_path / "module.py", "module") diff --git a/src/trio/_tests/tools/test_sync_requirements.py b/src/trio/_tests/tools/test_sync_requirements.py index 92b3bfdd97..5beb707558 100644 --- a/src/trio/_tests/tools/test_sync_requirements.py +++ b/src/trio/_tests/tools/test_sync_requirements.py @@ -2,13 +2,13 @@ from typing import TYPE_CHECKING -from trio._tests.pytest_plugin import skip_if_optional_else_raise +from trio._tests.pytest_plugin import maybe_ignore_import_error # imports in gen_exports that are not in `install_requires` in requirements try: import yaml # noqa: F401 except ImportError as error: - skip_if_optional_else_raise(error) + maybe_ignore_import_error(error) from trio._tools.sync_requirements import ( update_requirements, diff --git a/test-requirements.txt b/test-requirements.txt index 96e65ac31d..80c2bf538b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -39,7 +39,7 @@ colorama==0.4.6 ; sys_platform == 'win32' # sphinx coverage==7.16.0 # via -r test-requirements.in -cryptography==48.0.0 +cryptography==50.0.1 # via # -r test-requirements.in # pyopenssl @@ -126,7 +126,7 @@ pygments==2.21.0 # sphinx pylint==4.0.8 # via -r test-requirements.in -pyopenssl==26.2.0 +pyopenssl==26.4.0 # via -r test-requirements.in pyright==1.1.411 # via -r test-requirements.in