skip to navigation
skip to content

Not Logged In

pytest-sftpserver 1.0.2

py.test plugin to locally test sftp server connections.

Latest Version: 1.1.1

pytest-sftpserver is a plugin for pytest that provides a local SFTP-Server fixture.

The SFTP-Server provided by this fixture serves content not from files but directly from Python objects.

Quickstart

Assume you want to test a function that downloads a file from an SFTP-Server:

from contextlib import closing
import paramiko
def get_sftp_file(host, port, username, password, path):
    with closing(paramiko.Transport((host, port))) as transport:
        transport.connect(username=username, password=password)
        with closing(paramiko.SFTPClient.from_transport(transport)) as sftpclient:
            with sftpclient.open(path, "r") as sftp_file:
                return sftp_file.read()

This plugin allows to test such functions without having to spin up an external SFTP-Server by providing a pytest fixture called sftpserver. You use it simply by adding a parameter named sftpserver to your test function:

def test_sftp_fetch(sftpserver):
    with sftpserver.serve_content({'a_dir': {'somefile.txt': "File content"}}):
        assert get_sftp_file(sftpserver.host, sftpserver.port, "user",
                             "pw", "/a_dir/somefile.txt") == "File content"

As can be seen from this example sftpserver serves content directly from python objects instead of files.

Installation

pip install pytest-sftpserver

Supported Python versions

This package supports the following Python versions:

  • 2.6 - 2.7
  • 3.2 - 3.4

TODO

  • Add more documentation
  • Add more usage examples
  • Add TODOs :)

License

Licensed unter the MIT License. See file LICENSE.

Inspiration

The implementation and idea for this plugin is in part based upon:

 
File Type Py Version Uploaded on Size
pytest-sftpserver-1.0.2.tar.gz (md5) Source 2014-07-27 10KB
pytest_sftpserver-1.0.2-py2.py3-none-any.whl (md5) Python Wheel 2.7 2014-07-27 18KB
  • Downloads (All Versions):
  • 38 downloads in the last day
  • 268 downloads in the last week
  • 1077 downloads in the last month