Remove debugging-only code and add missing docstring in pytest fixtures
Marco Ricci

Marco Ricci commited on 2024-09-22 19:19:38
Zeige 1 geänderte Dateien mit 38 Einfügungen und 5 Löschungen.

... ...
@@ -423,11 +423,11 @@ def spawn_ssh_agent(
423 423
                     client.list_keys()
424 424
                 except KeyError:  # pragma: no cover
425 425
                     pytest.skip('SSH agent is not running')
426
-                # except OSError as exc:  # pragma: no cover
427
-                #     pytest.skip(
428
-                #         f'Cannot talk to SSH agent: '
429
-                #         f'{exc.strerror}: {exc.filename!r}'
430
-                #     )
426
+                except OSError as exc:  # pragma: no cover
427
+                    pytest.skip(
428
+                        f'Cannot talk to SSH agent: '
429
+                        f'{exc.strerror}: {exc.filename!r}'
430
+                    )
431 431
                 with client:
432 432
                     assert (
433 433
                         os.environ.get('SSH_AUTH_SOCK', None)
... ...
@@ -510,6 +510,39 @@ def spawn_ssh_agent(
510 510
 def ssh_agent_client_with_test_keys_loaded(  # noqa: C901
511 511
     spawn_ssh_agent: tests.SpawnedSSHAgentInfo,
512 512
 ) -> Iterator[ssh_agent.SSHAgentClient]:
513
+    """Provide an SSH agent with loaded test keys, as a pytest fixture.
514
+
515
+    Use the `spawn_ssh_agent` fixture to acquire a usable SSH agent,
516
+    upload the known test keys into the agent, and return a connected
517
+    client.
518
+
519
+    The agent may reject several of the test keys due to unsupported or
520
+    obsolete key types.  Rejected keys will be silently ignored, unless
521
+    all keys are rejected; then the test will be skipped.  You must not
522
+    automatically assume any particular key is present in the agent.
523
+
524
+    Yields:
525
+        (ssh_agent.SSHAgentClient):
526
+            A [named tuple][collection.namedtuple] containing
527
+            information about the spawned agent, e.g. the software
528
+            product, a client connected to the agent, and whether the
529
+            agent is isolated from other clients.
530
+
531
+    Raises:
532
+        OSError:
533
+            There was a communication or a socket setup error with the
534
+            agent.
535
+        pytest.skip.Exception:
536
+            If the agent is unusable or if it rejected all test keys,
537
+            skip this test.
538
+
539
+    Warning:
540
+        It is the fixture's responsibility to clean up the SSH agent
541
+        client after the test.  Closing the client's socket connection
542
+        beforehand (e.g. by using the client as a context manager) may
543
+        lead to exceptions being thrown upon fixture teardown.
544
+
545
+    """
513 546
     agent_type, client, isolated = spawn_ssh_agent
514 547
     all_test_keys = {**tests.SUPPORTED_KEYS, **tests.UNSUITABLE_KEYS}
515 548
     successfully_loaded_keys: set[str] = set()
516 549