scitacean.testing.backend#

Utilities for running tests against a locally deployed SciCat backend.

This subpackage provides tools for using a real SciCat backend running in docker containers on the local machine. It, therefore, requires docker to be installed and running. The package is in particular intended to be used with pytest and the fixtures provided by the scitacean.testing.backend.fixtures submodule. But it is also possible to set up tests in a different way by using the functions provided here.

Note

Although this package attempts to clean up after itself, it is possible that it fails to tear down the backend completely if tests are aborted in an unusual way (pressing Ctrl-C is fine). If this happens, a running docker container may be left behind. It needs to be stopped manually. Failing this, future tests may freeze indefinitely during start up.

Attention

The fixtures support pytest-xdist but only if all workers run on the local machine (the default).

It may still happen that tests fail due to the complexity of synchronizing start up and shut down of the backend between workers.

See also

Testing user guide.

Examples

The following pytest test will download the “raw” dataset that is included in the seed. It runs both with a real and a fake client.

from scitacean.testing.backend import seed

def test_download(client):
    ds = client.get_dataset(seed.INITIAL_DATASETS["raw"].pid)
    # assert something

If a test requires a backend but wants to construct a client manually, use

def test_manual_client(require_scicat_backend, scicat_access):
    client = Client.from_credentials(
        url=scicat_access.url,
        **scicat_access.user.credentials
    )
    # assert something

Functions

add_pytest_options(parser[, option])

Add command-line options to pytest to control backend tests.

backend_enabled(request)

Return True if backend tests are enabled.

configure(target_path, *[, version])

Build a docker-compose file for the testing backend.

skip_if_not_backend(request)

Mark the current test to be skipped if backend tests are disabled.

start_backend(docker_compose_file)

Start the docker container with SciCat backend.

stop_backend(docker_compose_file)

Stop the docker container with SciCat backend and remove volumes.

wait_until_backend_is_live(max_time, n_tries)

Sleep until a connection to the backend can be made.

Modules

config

Backend configuration.

fixtures

Pytest fixtures to manage and access a local SciCat backend.

seed

Initial contents of the SciCat testing backend.