|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import functools |
| 6 | +import importlib.metadata |
6 | 7 | import pathlib |
7 | 8 | import sys |
8 | 9 | from collections.abc import Generator, Sequence |
9 | | -from typing import Protocol |
| 10 | +from typing import Any, Protocol |
10 | 11 |
|
11 | 12 | import pytest |
12 | 13 | from click.testing import CliRunner, Result |
13 | 14 | from ni_measurement_plugin_sdk_service.discovery._support import ( |
14 | 15 | _get_registration_json_file_path, |
15 | 16 | ) |
| 17 | +from packaging.version import Version |
16 | 18 |
|
17 | 19 | import ni_measurement_plugin_sdk_generator.client as client_generator |
18 | 20 | import ni_measurement_plugin_sdk_generator.plugin as plugin_generator |
@@ -58,14 +60,22 @@ def pin_map_directory(test_assets_directory: pathlib.Path) -> pathlib.Path: |
58 | 60 | @pytest.fixture(scope="session") |
59 | 61 | def create_client() -> Generator[CliRunnerFunction]: |
60 | 62 | """Test fixture for calling client generator cli.""" |
61 | | - runner = CliRunner(mix_stderr=False) |
| 63 | + runner = _create_clirunner() |
62 | 64 | yield functools.partial(runner.invoke, client_generator.create_client, standalone_mode=False) |
63 | 65 |
|
64 | 66 |
|
65 | 67 | @pytest.fixture(scope="session") |
66 | 68 | def create_measurement() -> Generator[CliRunnerFunction]: |
67 | 69 | """Test fixture for calling plugin generator cli.""" |
68 | | - runner = CliRunner(mix_stderr=False) |
| 70 | + runner = _create_clirunner() |
69 | 71 | yield functools.partial( |
70 | 72 | runner.invoke, plugin_generator.create_measurement, standalone_mode=False |
71 | 73 | ) |
| 74 | + |
| 75 | + |
| 76 | +def _create_clirunner() -> CliRunner: |
| 77 | + kwargs: dict[str, Any] = {} |
| 78 | + if Version(importlib.metadata.version("click")) < Version("8.2.0"): |
| 79 | + # mix_stderr was removed in click 8.2. |
| 80 | + kwargs["mix_stderr"] = False |
| 81 | + return CliRunner(**kwargs) |
0 commit comments