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-sftpserverVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.