Designing unit tests for paramiko wrapper
Single responsibility principle

This function does too many things:


maybe it copies a remote file
maybe it prints info


The function may also print timing stats, which probably doesn't make much sense when not copying the remote file.

Unit testing is most effective when testing small independent units that have a single responsibility, well-defined inputs and outputs, and ideally no side effects.

As a first step, it would be good to split this function to multiple smaller functions:

def get_remote_file(filepath, time=False):
    # ...

def get_local_file(filepath):
    # ...

def get_file(filepath, time=False, copy_to_local=False):
    if copy_to_local:
        return get_remote_file(filepath, time)
    return get_local_file(filepath)

def print_file_info(filepath, file):
    # ...


Each of these functions have well-defined, simpler responsibilities.
The get_file function may seem to do multiple things,
but it's ok, as it only orchestrates those things,
it's more of a controller and has trivially simple implementation.

Now that you have smaller units,
you can think about testing them individually, if necessary.
Actually I don't see much to test here,
because of the code is either printing,
or making paramiko API calls.
Testing that the paramiko calls work and you can fetch files will not be unit testing anymore,
because it will require external factors correctly setup,
such as a remote server with a file at a specific location,
which would violate the principle of unit testing.
That is not to say it's not worth testing,
maybe it is, to test your setup,
but it's not "unit testing", it's integration testing.

Code review

There is just one part that might be worth testing:


user = filepath.split(':')[0].split('@')[0]
host = filepath.split(':')[0].split('@')[1]
rfile = filepath.split(':')[1]



I suggest to put this in a function of its own:

def split_ssh_filepath(filepath):
    user = filepath.split(':')[0].split('@')[0]
    host = filepath.split(':')[0].split('@')[1]
    rfile = filepath.split(':')[1]
    return user, host, rfile


And eliminate the repeated calls to filepath.split:

def split_ssh_filepath(ssh_filepath):
    user_host_rfile = ssh_filepath.split(':')[:2]
    user, host = user_host_rfile[0].split('@')[:2]
    rfile = user_host_rfile[1]
    return user, host, rfile