{"id":4723,"library":"pytest-sftpserver","title":"pytest-sftpserver","description":"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.","status":"maintenance","version":"1.3.0","language":"en","source_language":"en","source_url":"http://github.com/ulope/pytest-sftpserver/","tags":["pytest","sftp","testing","fixtures","paramiko"],"install":[{"cmd":"pip install pytest-sftpserver","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for any pytest plugin functionality.","package":"pytest","optional":false}],"imports":[{"note":"The 'sftpserver' is a pytest fixture provided by the plugin and is injected directly into test functions as an argument.","symbol":"sftpserver","correct":"def test_my_sftp_client(sftpserver): ..."}],"quickstart":{"code":"from contextlib import closing\nimport paramiko\nimport pytest\nimport os\n\n# Helper function that would typically be part of your application code\ndef get_sftp_file(host, port, username, password, path):\n    with closing(paramiko.Transport((host, port))) as transport:\n        transport.connect(username=username, password=password)\n        with closing(paramiko.SFTPClient.from_transport(transport)) as sftpclient:\n            with sftpclient.open(path, \"r\") as sftp_file:\n                return sftp_file.read().decode('utf-8')\n\n# A test function using the sftpserver fixture\ndef test_sftp_fetch(sftpserver):\n    # The sftpserver fixture is automatically discovered and injected\n    # It serves content from Python objects (dictionaries)\n    with sftpserver.serve_content({'a_dir': {'somefile.txt': b\"File content\"}}):\n        # Use environment variables or dummy values for actual connection\n        # In a real scenario, these might come from test configuration\n        assert get_sftp_file(sftpserver.host, sftpserver.port, \"user\", \"pw\", \"/a_dir/somefile.txt\") == \"File content\"\n","lang":"python","description":"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."},"warnings":[{"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.","message":"Python 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.","severity":"breaking","affected_versions":"<=1.3.0"},{"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.","message":"Tests 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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"In-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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}