pytest-localftpserver
raw JSON → 1.5.0 verified Fri May 01 auth: no python maintenance
A PyTest plugin that provides an FTP fixture (localftpserver) for your tests, enabling you to spin up a real FTP server during testing. Version 1.5.0 is the latest release; the project is in maintenance mode with infrequent updates.
pip install pytest-localftpserver Common errors
error NameError: name 'localftpserver' is not defined ↓
cause The fixture is not imported; it's automatically provided by the plugin when installed.
fix
Ensure pytest-localftpserver is installed and you didn't try to import the fixture manually. Just use it as a test parameter.
error AttributeError: 'str' object has no attribute 'session' ↓
cause Using 'localftpserver' as a string variable instead of the fixture name.
fix
Do not assign the fixture name to a string; let pytest inject the fixture object via the function argument.
error OSError: [Errno 98] Address already in use ↓
cause The FTP server port is already in use (e.g., from a previous test that didn't shut down).
fix
Ensure each test cleans up after itself. You can also specify a different port via --localftpserver-port option.
Warnings
gotcha The fixture starts a real FTP server on a random port; ensure you don't have conflicting services or firewall restrictions. ↓
fix Use the default configuration or set the port via pytest options.
deprecated The project has not been updated in years and may have compatibility issues with newer Python versions or pytest 7+. ↓
fix Consider using alternative solutions like pyftpdlib directly or pytest-docker for FTP testing.
gotcha The fixture does not clean up the server after each test by default; ensure you close sessions properly to avoid hanging processes. ↓
fix Always use the session() context manager or manually close the FTP client.
Imports
- localftpserver
no import needed; use fixture name in test function argument
Quickstart
def test_ftp(localftpserver):
with localftpserver.session() as ftp:
ftp.login('user', 'pass')
ftp.cwd('/')
assert ftp.pwd() == '/'
ftp.storbinary('STOR testfile', b'data')
ftp.retrbinary('RETR testfile', lambda x: None)