I am creating unit tests for a girder plugin, using a structure similar to the one used in the dicom_viewer , but I have a problem with the
So you’re using cmake and unittest instead of pytest?
To make it short, I have girder exception:
An assetstore with that name already exists if the
setUp function is called more than once.
This sounds right,
setUp isn’t meant to be called more than once. In fact, I don’t think
setUp is supposed to be invoked by the caller - the unittest module takes care of calling it for you.
To go further into the details, I have notice that during the
setUp function, my table girder_test_plugin (coming from the girder config) is not really dropped but replaced by another table girder_test_[a long hash] .
I’m a bit confused here because the hash is created by pytest. However, pytest tests don’t have a
setUp function, they use fixtures for setup and teardown.
For background on the hashing: the pytest runner sets up a database for each test function, and the old runner (unittest/cmake) set up a database per module. Since test function names can be long (
test_my_function_does_this_correctly) and Mongo doesn’t allow extremely long database names, we hash the function name to truncate it in a way that provides uniqueness.
The cookiecutter plugin really is the best reference here. It doesn’t include a test that accesses the database, but that’s as simple as writing a regular pytest test that has a
db fixture in the argument list. In fact, once pytest is installed you can view the fixtures provided by pytest-girder by running
----------------- fixtures defined from pytest_girder.fixtures -----------------
smtp -- pytest_girder/pytest_girder/fixtures.py:137
Provides a mock SMTP server for testing.
admin -- pytest_girder/pytest_girder/fixtures.py:161
Require an admin user.
Provides a user with the admin flag set to True.
user -- pytest_girder/pytest_girder/fixtures.py:175
Require a user.
Provides a regular user with no additional privileges. Note this fixture requires
the admin fixture since an administrative user must exist before a regular user can.
fsAssetstore -- pytest_girder/pytest_girder/fixtures.py:190
Require a filesystem assetstore. Its location will be derived from the test function name.
bcrypt -- pytest_girder/pytest_girder/fixtures.py:21
Mock out bcrypt password hashing to avoid unnecessary testing bottlenecks.
db -- pytest_girder/pytest_girder/fixtures.py:31
Require a Mongo test database.
Provides a Mongo test database named after the requesting test function. Mongo databases are
created/destroyed based on the URI provided with the --mongo-uri option and tear-down
behavior is modified by the --keep-db option.
server -- pytest_girder/pytest_girder/fixtures.py:79
Require a CherryPy embedded server.
Provides a started CherryPy embedded server with a request method for performing
local requests against it. Note: this fixture requires the db fixture.