Marco Ricci commited on 2026-07-05 11:13:19
Zeige 5 geänderte Dateien mit 28 Einfügungen und 71 Löschungen.
This avoids redefining the same fixture in multiple test modules.
| ... | ... |
@@ -105,6 +105,34 @@ def skip_if_no_ctypes_windll_support() -> None: # pragma: no cover [external] |
| 105 | 105 |
) |
| 106 | 106 |
|
| 107 | 107 |
|
| 108 |
+@pytest.fixture |
|
| 109 |
+def use_stub_agent() -> Generator[None, None, None]: |
|
| 110 |
+ """Enforce use of the stubbed SSH agent.""" |
|
| 111 |
+ with pytest.MonkeyPatch.context() as monkeypatch: |
|
| 112 |
+ monkeypatch.setattr( |
|
| 113 |
+ ssh_agent.SSHAgentClient, |
|
| 114 |
+ "SOCKET_PROVIDERS", |
|
| 115 |
+ (_types.BuiltinSSHAgentSocketProvider.STUB_AGENT,), |
|
| 116 |
+ ) |
|
| 117 |
+ monkeypatch.delenv("SSH_AUTH_SOCK", raising=False)
|
|
| 118 |
+ yield |
|
| 119 |
+ |
|
| 120 |
+ |
|
| 121 |
+@pytest.fixture |
|
| 122 |
+def use_stub_agent_with_address() -> Generator[None, None, None]: |
|
| 123 |
+ """Enforce use of the stub SSH agent with socket address.""" |
|
| 124 |
+ with pytest.MonkeyPatch.context() as monkeypatch: |
|
| 125 |
+ monkeypatch.setattr( |
|
| 126 |
+ ssh_agent.SSHAgentClient, |
|
| 127 |
+ "SOCKET_PROVIDERS", |
|
| 128 |
+ (_types.BuiltinSSHAgentSocketProvider.STUB_AGENT_WITH_ADDRESS,), |
|
| 129 |
+ ) |
|
| 130 |
+ monkeypatch.setenv( |
|
| 131 |
+ "SSH_AUTH_SOCK", machinery.StubbedSSHAgentSocketWithAddress.ADDRESS |
|
| 132 |
+ ) |
|
| 133 |
+ yield |
|
| 134 |
+ |
|
| 135 |
+ |
|
| 108 | 136 |
class SSHAgentSpawnFunc(Protocol): |
| 109 | 137 |
"""Spawns an SSH agent, if possible.""" |
| 110 | 138 |
|
| ... | ... |
@@ -66,21 +66,6 @@ DUMMY_KEY3_B64 = data.DUMMY_KEY3_B64 |
| 66 | 66 |
TEST_CONFIGS = data.TEST_CONFIGS |
| 67 | 67 |
|
| 68 | 68 |
|
| 69 |
-@pytest.fixture |
|
| 70 |
-def use_stub_agent_with_address() -> Generator[None, None, None]: |
|
| 71 |
- """Enforce use of the stubbed SSH agent with socket address.""" |
|
| 72 |
- with pytest.MonkeyPatch.context() as monkeypatch: |
|
| 73 |
- monkeypatch.setattr( |
|
| 74 |
- ssh_agent.SSHAgentClient, |
|
| 75 |
- "SOCKET_PROVIDERS", |
|
| 76 |
- (_types.BuiltinSSHAgentSocketProvider.STUB_AGENT_WITH_ADDRESS,), |
|
| 77 |
- ) |
|
| 78 |
- monkeypatch.setenv( |
|
| 79 |
- "SSH_AUTH_SOCK", machinery.StubbedSSHAgentSocketWithAddress.ADDRESS |
|
| 80 |
- ) |
|
| 81 |
- yield |
|
| 82 |
- |
|
| 83 |
- |
|
| 84 | 69 |
def vault_config_exporter_shell_interpreter( # noqa: C901 |
| 85 | 70 |
script: str | Iterable[str], |
| 86 | 71 |
/, |
| ... | ... |
@@ -187,21 +187,6 @@ for opt, config in SINGLES.items(): |
| 187 | 187 |
) |
| 188 | 188 |
|
| 189 | 189 |
|
| 190 |
-@pytest.fixture |
|
| 191 |
-def use_stub_agent_with_address() -> Generator[None, None, None]: |
|
| 192 |
- """Enforce use of the stub SSH agent with socket address.""" |
|
| 193 |
- with pytest.MonkeyPatch.context() as monkeypatch: |
|
| 194 |
- monkeypatch.setattr( |
|
| 195 |
- ssh_agent.SSHAgentClient, |
|
| 196 |
- "SOCKET_PROVIDERS", |
|
| 197 |
- (_types.BuiltinSSHAgentSocketProvider.STUB_AGENT_WITH_ADDRESS,), |
|
| 198 |
- ) |
|
| 199 |
- monkeypatch.setenv( |
|
| 200 |
- "SSH_AUTH_SOCK", machinery.StubbedSSHAgentSocketWithAddress.ADDRESS |
|
| 201 |
- ) |
|
| 202 |
- yield |
|
| 203 |
- |
|
| 204 |
- |
|
| 205 | 190 |
def is_warning_line(line: str) -> bool: |
| 206 | 191 |
"""Return true if the line is a warning line.""" |
| 207 | 192 |
return " Warning: " in line or " Deprecation warning: " in line |
| ... | ... |
@@ -47,34 +47,6 @@ DUMMY_SERVICE = data.DUMMY_SERVICE |
| 47 | 47 |
DUMMY_KEY1_B64 = data.DUMMY_KEY1_B64 |
| 48 | 48 |
|
| 49 | 49 |
|
| 50 |
-@pytest.fixture |
|
| 51 |
-def use_stub_agent() -> Generator[None, None, None]: |
|
| 52 |
- """Enforce use of the stubbed SSH agent.""" |
|
| 53 |
- with pytest.MonkeyPatch.context() as monkeypatch: |
|
| 54 |
- monkeypatch.setattr( |
|
| 55 |
- ssh_agent.SSHAgentClient, |
|
| 56 |
- "SOCKET_PROVIDERS", |
|
| 57 |
- (_types.BuiltinSSHAgentSocketProvider.STUB_AGENT,), |
|
| 58 |
- ) |
|
| 59 |
- monkeypatch.delenv("SSH_AUTH_SOCK", raising=False)
|
|
| 60 |
- yield |
|
| 61 |
- |
|
| 62 |
- |
|
| 63 |
-@pytest.fixture |
|
| 64 |
-def use_stub_agent_with_address() -> Generator[None, None, None]: |
|
| 65 |
- """Enforce use of the stubbed SSH agent with socket address.""" |
|
| 66 |
- with pytest.MonkeyPatch.context() as monkeypatch: |
|
| 67 |
- monkeypatch.setattr( |
|
| 68 |
- ssh_agent.SSHAgentClient, |
|
| 69 |
- "SOCKET_PROVIDERS", |
|
| 70 |
- (_types.BuiltinSSHAgentSocketProvider.STUB_AGENT_WITH_ADDRESS,), |
|
| 71 |
- ) |
|
| 72 |
- monkeypatch.setenv( |
|
| 73 |
- "SSH_AUTH_SOCK", machinery.StubbedSSHAgentSocketWithAddress.ADDRESS |
|
| 74 |
- ) |
|
| 75 |
- yield |
|
| 76 |
- |
|
| 77 |
- |
|
| 78 | 50 |
def is_harmless_config_import_warning(record: tuple[str, int, str]) -> bool: |
| 79 | 51 |
"""Return true if the warning is harmless, during config import.""" |
| 80 | 52 |
possible_warnings = [ |
| ... | ... |
@@ -41,19 +41,6 @@ if sys.version_info < (3, 11): |
| 41 | 41 |
from exceptiongroup import ExceptionGroup |
| 42 | 42 |
|
| 43 | 43 |
|
| 44 |
-@pytest.fixture |
|
| 45 |
-def use_stub_agent() -> Generator[None, None, None]: |
|
| 46 |
- """Enforce use of the stubbed SSH agent.""" |
|
| 47 |
- with pytest.MonkeyPatch.context() as monkeypatch: |
|
| 48 |
- monkeypatch.setattr( |
|
| 49 |
- ssh_agent.SSHAgentClient, |
|
| 50 |
- "SOCKET_PROVIDERS", |
|
| 51 |
- (_types.BuiltinSSHAgentSocketProvider.STUB_AGENT,), |
|
| 52 |
- ) |
|
| 53 |
- monkeypatch.delenv("SSH_AUTH_SOCK", raising=False)
|
|
| 54 |
- yield |
|
| 55 |
- |
|
| 56 |
- |
|
| 57 | 44 |
class Parametrize(pytest_machinery.Parametrize): |
| 58 | 45 |
BAD_ENTRY_POINTS = pytest.mark.parametrize( |
| 59 | 46 |
"additional_entry_points", |
| 60 | 47 |