pytest-servers

raw JSON →
0.5.13 verified Mon Apr 27 auth: no python

Pytest plugin providing fixtures for local mock servers (S3, GCS, Azure Blob, SFTP) using Docker containers. Version 0.5.13, actively maintained with frequent minor releases.

pip install pytest-servers
error ModuleNotFoundError: No module named 'pytest_servers'
cause pytest-servers is not installed or the import path is wrong.
fix
Install with pip install pytest-servers and use correct import: from pytest_servers.s3 import s3_server.
error docker.errors.DockerException: Error while fetching server API version: ...
cause Docker daemon is not running or the user does not have permissions.
fix
Start Docker and ensure your user has access (e.g., add to docker group).
error pytest fixture 's3_server' not found
cause The fixture is not registered; likely missing the plugin or import.
fix
Install pytest-servers and either use pytest_plugins = ['pytest_servers.s3'] in conftest or import the fixture directly.
breaking The 'gs' alias for 'gcs' was added in 0.5.4. Previously, only 'gcs' was accepted.
fix Upgrade to >=0.5.4 to use 'gs' as a server type, or continue using 'gcs'.
deprecated The fixture names are subject to change; check the latest docs for exact names.
fix Use explicit imports from submodules to avoid future breakage.
gotcha Docker is required; the plugin will fail if Docker is not running or not installed.
fix Ensure Docker is installed and the daemon is running before using fixtures.
gotcha Port conflicts: if the default port (e.g., 9000 for minio) is already in use, the fixture will fail.
fix Check port availability or adjust via environment variables (if supported).
pip install 'pytest-servers[s3]'
pip install 'pytest-servers[gcs]'
pip install 'pytest-servers[azure]'
pip install 'pytest-servers[sftp]'

Use fixtures to start local mock servers for testing cloud storage integrations.

import pytest
from pytest_servers.s3 import s3_server
from pytest_servers.gcs import gcs_server
from pytest_servers.azure import azurite_server
from pytest_servers.sftp import sftp_server

@pytest.mark.usefixtures('s3_server')
def test_s3():
    # s3_server fixture starts a mock S3 server (using minio) in a Docker container
    # The endpoint is available via os.environ['AWS_ENDPOINT_URL']
    import os
    assert 'AWS_ENDPOINT_URL' in os.environ
    print(f"S3 endpoint: {os.environ['AWS_ENDPOINT_URL']}")

@pytest.mark.usefixtures('gcs_server')
def test_gcs():
    import os
    assert 'STORAGE_EMULATOR_HOST' in os.environ
    print(f"GCS endpoint: {os.environ['STORAGE_EMULATOR_HOST']}")

@pytest.mark.usefixtures('azurite_server')
def test_azure():
    import os
    assert 'AZURITE_HOST' in os.environ
    print(f"Azure endpoint: {os.environ['AZURITE_HOST']}")

@pytest.mark.usefixtures('sftp_server')
def test_sftp():
    import os
    assert 'SFTP_HOST' in os.environ
    print(f"SFTP endpoint: {os.environ['SFTP_HOST']}")