Skip to content

Client Integration

Nicolas Couture edited this page Apr 19, 2026 · 2 revisions

Client Integration (Paramiko)

While MockSSH works with any SSH client, Paramiko is the most common choice for Python-based automation tests.

Basic Test Example

import paramiko
import pytest

def test_device_config(ssh_client):
    """
    Assumes 'ssh_client' is a fixture that returns 
    an authenticated paramiko.SSHClient instance.
    """
    channel = ssh_client.invoke_shell()
    
    # Send a command
    channel.send("show version\n")
    
    # Wait for and read the response
    while not channel.recv_ready():
        time.sleep(0.1)
    output = channel.recv(1024).decode("utf-8")
    
    assert "MockSSH version 2.0" in output

Security Best Practices in Tests

When connecting to the mock server, you should disable the system's SSH agent to avoid environment-specific signing errors:

ssh.connect(
    "127.0.0.1",
    username="admin",
    password="x",
    port=server.getHost().port,  # Use the dynamically assigned port
    allow_agent=False,           # CRITICAL
    look_for_keys=False          # CRITICAL
)

Clone this wiki locally