Marco Ricci commited on 2026-06-21 22:00:04
Zeige 2 geänderte Dateien mit 20 Einfügungen und 5 Löschungen.
This allows finding tests which use external SSH agents more easily, so that they may be better evaluated for necessity of such agent use.
| ... | ... |
@@ -42,6 +42,13 @@ def pytest_configure(config: pytest.Config) -> None: |
| 42 | 42 |
"mark test as a potentially slow, correctness-focused test" |
| 43 | 43 |
), |
| 44 | 44 |
) |
| 45 |
+ config.addinivalue_line( |
|
| 46 |
+ "markers", |
|
| 47 |
+ ( |
|
| 48 |
+ "external_agent: " |
|
| 49 |
+ "mark the agent (fixture output) as external to the test suite" |
|
| 50 |
+ ), |
|
| 51 |
+ ) |
|
| 45 | 52 |
config.addinivalue_line( |
| 46 | 53 |
"markers", |
| 47 | 54 |
( |
| ... | ... |
@@ -534,18 +541,26 @@ for instance, handler in spawn_handlers.items(): |
| 534 | 541 |
"environment variable.", |
| 535 | 542 |
), |
| 536 | 543 |
] |
| 544 |
+ agent_type = handler.instance.agent_type |
|
| 545 |
+ # Distinguish spawned/interfaced agents ("external agents") from the
|
|
| 546 |
+ # stub agents ("internal agents"). While this could be inferred from
|
|
| 547 |
+ # the other marks, it is sensible to have a dedicated mark for this. |
|
| 548 |
+ # Tests that unnecessarily use external agents without testing anything |
|
| 549 |
+ # that is specific to external agents can be found more easily using |
|
| 550 |
+ # this mark, and converted to using internal agents only, with speed and |
|
| 551 |
+ # flakiness-resistance benefits. |
|
| 552 |
+ if agent_type != data.KnownSSHAgentType.StubbedSSHAgent: |
|
| 553 |
+ marks.append(pytest.mark.external_agent) |
|
| 537 | 554 |
# Allow agents to be marked as non-reentrant. Workaround for an |
| 538 | 555 |
# issue with GnuPG 2.4.8 on The Annoying OS when `gpg-agent` |
| 539 | 556 |
# masquerades as OpenSSH's `ssh-agent`. |
| 540 |
- if is_agent_non_reentrant( |
|
| 541 |
- handler.instance.agent_type |
|
| 542 |
- ): # pragma: no cover [external] |
|
| 557 |
+ if is_agent_non_reentrant(agent_type): # pragma: no cover [external] |
|
| 543 | 558 |
marks.append(pytest.mark.non_reentrant_agent) |
| 544 | 559 |
# Mark non-isolated agents as, well, using non-isolated agents. |
| 545 | 560 |
# Assume by default that an agent is potentially non-isolated unless |
| 546 | 561 |
# we can be absolutely sure it is isolated, by design. (The "stub" |
| 547 | 562 |
# agents fall into the latter category.) |
| 548 |
- if handler.instance.agent_type != data.KnownSSHAgentType.StubbedSSHAgent: |
|
| 563 |
+ if agent_type != data.KnownSSHAgentType.StubbedSSHAgent: |
|
| 549 | 564 |
marks.append(pytest_machinery.non_isolated_agent_use) |
| 550 | 565 |
# Some agents require UNIX domain socket support. |
| 551 | 566 |
if instance in {
|
| ... | ... |
@@ -244,7 +244,7 @@ class KnownSSHAgentInstance(str, enum.Enum): |
| 244 | 244 |
|
| 245 | 245 |
@property |
| 246 | 246 |
def agent_type(self) -> KnownSSHAgentType: |
| 247 |
- """Return the agent type for this instance.""" |
|
| 247 |
+ """The agent type for this instance.""" |
|
| 248 | 248 |
# TODO(the-13th-letter): Rewrite using structural pattern |
| 249 | 249 |
# matching. |
| 250 | 250 |
# https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9 |
| 251 | 251 |