| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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.
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.
pip install pytest-sftpserver
This package supports the following Python versions:
Updated supported Python versions to 2.7, 3.5 - 3.7.
Droped (official) support for 3.4.
Check / format code with black, isort and flake8.
Fix return type of .read(). (#15, thanks @WeatherGod)
Support the offset parameter on write operations. (#11, #16, thanks @DrNecromant)
Thanks to @zerok for both bug reports and accompanying tests.
Licensed unter the MIT License. See file LICENSE.
The implementation and idea for this plugin is in part based upon:
| Back | FazBrowse Home | New Git URL |