linkahead.utils.register_tests module#

This module implements a registration procedure for integration tests which need a running LinkAhead instance.

It ensures that tests do not accidentally overwrite data in real LinkAhead instances, as it checks whether the running LinkAhead instance is actually the correct one, that should be used for these tests.

The test files have to define a global variable TEST_KEY which must be unique for each test using set_test_key().

The test procedure (invoked by pytest) checks whether a registration information is stored in one of the server properties or otherwise

  • offers to register this test in the currently running database ONLY if this is empty.

  • fails otherwise with a RuntimeError

Note

you probably need to use pytest with the -s option to be able to register the test interactively. Otherwise, the server property has to be set before server start-up in the server.conf of the LinkAhead server.

This module is intended to be used with pytest.

There is a pytest fixture clear_database() that performs the above mentioned checks and clears the database in case of success.

linkahead.utils.register_tests.clear_database()#

Remove Records, RecordTypes, Properties, and Files ONLY IF the LinkAhead server the current connection points to was registered with the appropriate key using set_test_key().

PyTestInfo Records and the corresponding RecordType and Property are preserved.

linkahead.utils.register_tests.set_test_key(KEY: str)#

Set the global TEST_KEY variable to KEY. Afterwards, if KEY matches the _CAOSDB_INTEGRATION_TEST_SUITE_KEY server environment variable, methods like clear_database() can be used. Call this function in the beginning of your test file.

Parameters:

KEY (str) – key with which the test using this function is registered and which is checked against the _CAOSDB_INTEGRATION_TEST_SUITE_KEY server environment variable.