Skip to main content

pytest servers

Project description

pytest servers

PyPI Status Python Version License

Tests Codecov pre-commit Black

Features

Create temporary directories on the following filesystems:

Installation

You can install pytest servers via pip from PyPI:

$ pip install pytest-servers

To use temporary S3 paths:

$ pip install pytest-servers[s3]

To use temporary Azure paths

$ pip install pytest-servers[azure]

To use temporary Google Cloud Storage paths

$ pip install pytest-servers[gcs]

To install all extras:

$ pip install pytest-servers[all]

Usage

The main fixture provided by pytest-servers provides is tmp_upath_factory, which can be used to generate temporary paths on different (mocked) filesystems:

def test_something_on_s3(tmp_upath_factory):
    path = tmp_upath_factory.mktemp("s3")
    foo = path / "foo"
    foo.write_text("foo")
    ...

mktemp supports the following filesystem types:

  • local (local filesystem)

  • memory (in-memory filesystem)

  • s3 (Amazon S3)

  • gcs (Google Cloud Storage)

  • azure (Azure Storage)

Some convenience fixtures that wrap tmp_upath_factory.mktemp and return a paths on these filesystems are also available:

  • tmp_local_path

  • tmp_memory_path

  • tmp_s3_path

  • tmp_gcs_path

  • tmp_azure_path

The tmp_upath fixture can be used for parametrizing paths with pytest’s indirect parametrization:

@pytest.mark.parametrize("tmp_upath", ["local", "s3", "gcs"], indirect=True)
def test_something(tmp_upath):
    pass

In order to use real remotes instead of mocked ones, use tmp_upath_factory with the following methods

  • tmp_upath_factory.s3(region_name, client_kwargs) where client_kwargs are passed to the underlying S3FileSystem/boto client

  • tmp_upath_factory.gcs(endpoint_url)

  • tmp_upath_factory.azure(connection_string)

Versioning support can be used by using the versioning fixture. This is currently supported for s3 and gcs remotes

# using mktemp
def test_something_on_s3_versioned(tmp_upath_factory):
    path = tmp_upath_factory.mktemp("s3", version_aware=True)
    assert path.fs.version_aware # bucket has versioning enabled

# or, using remote-specific fixtures
def test_something_on_s3_versioned(tmp_s3_path, versioning):
    assert tmp_s3_path.fs.version_aware # bucket has versioning enabled

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the Apache 2.0 license, pytest servers is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-servers-0.5.1.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

pytest_servers-0.5.1-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-servers-0.5.1.tar.gz.

File metadata

  • Download URL: pytest-servers-0.5.1.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pytest-servers-0.5.1.tar.gz
Algorithm Hash digest
SHA256 366a45b4de2a3ce1727de16abe1327d215e2bbea79cfe138877bbd11ed9d352a
MD5 57fc2cb37e0d372a08cd4faa4fee3cf6
BLAKE2b-256 3205e2e2212eec577087d52ff36e4af47eaaae1ca97ebea6ba9080061a54f501

See more details on using hashes here.

File details

Details for the file pytest_servers-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_servers-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9f41645a76370ac2cc7a658993f08389350422ca0f434b78263bf09c87b1a522
MD5 c041f0d9e9f807f688b41c5b312fff28
BLAKE2b-256 58cbbbc964ab972c1ad0b0eb03459c647011d5f24d2aa27742c14081b975b50d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page