Skip to main content

dsemu

Description

dsemu is a simple library to help with testing GCP Datastore code written in Python. The provided Emulator class wraps the Datastore emulator and provides basic functionality such as starting/stopping and reseting the emulator instance from inside the test runner.

Requirements

You must have the gcloud tool installed and available in PATH.

Using existing instance of the emulator

If you're running tests that require datastore access frequently it might be better to keep an instance of the emulator running at all time instead of letting the wrapper start and stop it for the duration of the test run. If an instance of the emulator is running and the required environment variables are correctly set the Emulator wrapper will use the running instance instead of starting a new one and will not tear it down at the end of the test run.

Example usage with pytest

# conftest.py
import pytest
from dsemu import Emulator
from google.cloud import datastore


@pytest.fixture(scope="session")
def emulator():
    with Emulator() as emulator:
        yield emulator


@pytest.fixture(scope="session")
def session_client():
    client = datastore.Client(project="test")
    yield client


@pytest.fixture()
def client(emulator: Emulator, session_client: datastore.Client):
    emulator.reset()
    yield session_client
# datastore_test.py
from google.cloud import datastore


def test_datastore_put_and_get(client: datastore.Client):
    kind = "Task"
    name = "sampletask1"
    task_key = client.key(kind, name)
    task = datastore.Entity(key=task_key)
    task["description"] = "Buy milk"
    client.put(task)

    res = client.get(task_key)
    assert res == task

Metadata

Release files for dsemu 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dsemu 0.2.1
File Size Uploaded Provenance
dsemu-0.2.1.tar.gz 4.0 kB Without provenance Details

Release files / dsemu-0.2.1.tar.gz

Download URL dsemu-0.2.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
83600a83d14f49152b9024755c5eed2a3811f934ec5721f7ca887246101c44a6
BLAKE2b-256 checksum
How to use checksums
60da49685ab54b38680f0c325ec1ce13ea0a0d9bb0b1c159dac7f14ee7085541
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

Security for dsemu 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page