Registry / testing / pytest-sftpserver

pytest-sftpserver

JSON →
library1.3.0pypypi✓ verified 26d ago

pytest-sftpserver is a plugin for pytest that provides a local SFTP-Server fixture. The SFTP-Server provided by this fixture serves content directly from Python objects instead of files, simplifying local testing of SFTP client connections. The current version is 1.3.0, released in 2019, suggesting a moderate release cadence based on maintenance needs.

pip install pytest-sftpserver
INSTALL
IMPORT
SIG · PYTEST-SFTPSERVER
P
pytest-sftpserver
testingpythonv1.3.0
Install
3.0s avg
Import
—
Disk
41MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 42.7MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.0s · import 0.000s · 43MB
41MB installed
● package 41MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sftpserver
✓ def test_my_sftp_client(sftpserver): ...
The 'sftpserver' is a pytest fixture provided by the plugin and is injected directly into test functions as an argument.

To use `pytest-sftpserver`, define a test function that accepts the `sftpserver` fixture. Inside the test, use `sftpserver.serve_content()` as a context manager to specify the in-memory file structure to be served. Client code (e.g., using `paramiko`) can then connect to the SFTP server using `sftpserver.host` and `sftpserver.port` to interact with this content. Note that `paramiko` is a common dependency for client code interacting with the SFTP server, but not a direct dependency of the `pytest-sftpserver` plugin itself.

from contextlib import closing import paramiko import pytest import os # Helper function that would typically be part of your application code 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().decode('utf-8') # A test function using the sftpserver fixture def test_sftp_fetch(sftpserver): # The sftpserver fixture is automatically discovered and injected # It serves content from Python objects (dictionaries) with sftpserver.serve_content({'a_dir': {'somefile.txt': b"File content"}}): # Use environment variables or dummy values for actual connection # In a real scenario, these might come from test configuration assert get_sftp_file(sftpserver.host, sftpserver.port, "user", "pw", "/a_dir/somefile.txt") == "File content"
Debug
Known issues
breakingPython Version Support: The last release (1.3.0) officially supports Python 2.7, 3.5-3.7. It has not been updated since 2019, meaning newer Python versions (3.8+) are not officially supported and may lead to compatibility issues or unexpected behavior.
fix
Consider using Python 3.7 or older, or thoroughly test compatibility on newer Python versions. Be aware that no further updates are expected for newer Python versions.
affects: <=1.3.0
gotchaTests Hanging: Tests using the `sftpserver` fixture may hang indefinitely after completion if the SFTP client connections (e.g., `paramiko.Transport` or `paramiko.SFTPClient`) are not explicitly and gracefully closed.
fix
Ensure all SFTP client connections are properly terminated. Use `client.close()` methods or context managers like `contextlib.closing` for `paramiko` objects to guarantee closure, as demonstrated in the quickstart example.
affects: All
gotchaIn-Memory Content Only: The `sftpserver` fixture serves content directly from Python objects (dictionaries passed to `sftpserver.serve_content`) rather than interacting with actual files on the local filesystem.
fix
Design your tests to provide the SFTP server's content as a Python dictionary. Do not expect it to read or write to the actual filesystem of the test runner.
affects: All
Upgrade
Version history
1.3.0latest on PyPI · released Sep 16, 2019
Audit
Dependencies
pytestrequiredRequired for any pytest plugin functionality.
Agent activity
3 hits · last 30 days
node
2
Resources
pytest-sftpserver — pip install pytest-sftpserver · libregistry