{"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":"python","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,"search_vec":"'1.3.0':48 '2019':51 'base':57 'cadenc':56 'client':42 'connect':43 'content':29 'current':45 'direct':30 'file':36 'fixtur':19,27,64 'instead':34 'local':15,38 'mainten':59 'moder':54 'need':60 'object':33 'paramiko':65 'plugin':9 'provid':13,24 'pytest':2,5,11,61 'pytest-sftpserv':1,4 'python':32 'releas':49,55 'serv':28 'server':18,23 'sftp':17,22,41,62 'sftp-server':16,21 'sftpserver':3,6 'simplifi':37 'suggest':52 'test':39,63 'version':46","created_at":"2026-04-12T14:04:51.797608+00:00","updated_at":"2026-04-16T20:11:31.123272+00:00","problems":{"verify_error":"no import statement found"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.3.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"http://github.com/ulope/pytest-sftpserver","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pytest-sftpserver/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-05","install_tag":null}}