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 command-line options to pytest to control backend tests. |
|
Return True if backend tests are enabled. |
|
Build a docker-compose file for the testing backend. |
|
Mark the current test to be skipped if backend tests are disabled. |
|
Start the docker container with SciCat backend. |
|
Stop the docker container with SciCat backend and remove volumes. |
|
Sleep until a connection to the backend can be made. |
Modules