Skip to content

B2SHARE Unit tests#

B2SHARE has some unit tests in the site folder and customized Invenio modules.

Test structure#

tests/
  unit/                    # no Docker — run with python -m pytest
    conftest.py            # minimal, no stack deps
    test_refactor_unit.py  # 25 unit tests for T6/T7 refactoring
  integration/             # requires Docker stack — run via run-tests.sh
    conftest.py            # full InvenioRDM stack fixtures
    test_b2rec_provider_integration.py
    test_pyhandle_provider_integration.py
    resources/serializers/eudatcore/
      conftest.py          # record data fixtures
      test_serializer.py   # EUDAT Core serializer tests
    user_favourites/services/
      conftest.py          # create_app (create_api), identities, full_person
      test_creation.py     # user favourites service tests
  community_schema_extension/

Prerequisites and setup#

Prerequisites#

  • Python 3.14 or uv installed
  • Docker or Podman with podman-docker + docker-compose-v2
  • Application stack stopped

Setup#

In inveniordm_deployment/site:

Create a new virtual environment:

# With uv
uv venv --python 3.14 test-venv
# With python venv
python3.14 -m venv test-venv

# Start the venv
source test-venv/bin/activate

Install customized submodules:

python -m pip install -e "../customized_invenio_packages/invenio-rdm-records[tests,opensearch2]"
python -m pip install -e "../customized_invenio_packages/invenio-communities[tests,opensearch2]"
python -m pip install -e "../customized_invenio_packages/invenio-app-rdm[tests,opensearch2]"
python -m pip install -e "../customized_invenio_packages/invenio-vocabularies[tests,opensearch2]"
python -m pip install -e "../customized_invenio_packages/invenio-administration[tests,opensearch2]"
python -m pip install -e "../customized_invenio_packages/invenio-theme[tests,opensearch2]"

Install site package with test extras:

python -m pip install -e ".[tests,opensearch2]"

Note on setuptools: setuptools<81 is pinned in the test extras to preserve pkg_resources support needed by pyfilesystem2. Do not upgrade past 80.x.

Run the unit tests#

Even though some tests can be run without running the docker stack it is in most cases recommended to run the tests with the docker stack. However, it takes some time for the stack to start and for development purposes it can be better to run the tests without the stack.

To run the tests without the stack, run:

python -m pytest tests/unit -v

To run tests with the stack, run:

./run-tests.sh tests -v

The run-tests.sh takes all pytest arguments.

Run specific tests#

To run tests in a specific directory/file, run

./run-tests.sh tests/directory/file.py -v

To run a specific test, run:

# If test not in class
./run-tests.sh tests/directory/file.py::test_function_name -v
# If test in class
./run-tests.sh tests/directory/file.py::class_name::test_function_name -v

Ignore specific tests#

To ignore specific tests, run:

# Ignore in all in specific folder
./run-tests.sh tests/ --ignore=tests/folder -v
# Ignore tests in specific file
./run-tests.sh tests/ --ignore=tests/folder/file.py -v
# Ignore a specific test
./run-tests.sh tests/ --ignore=tests/folder/file.py::test_function_name -v
# OR
./run-tests.sh tests/ --ignore=tests/folder/file.py::class_name::test_function_name -v

Create coverage report#

To create a HTML coverage report, run:

# -ra gives short test summary info for all tests except passes
# -s disables stdout & stderr capturing
./run-tests.sh -ra -s -v --cov=b3share --cov-report html tests

The coverage report is generated to ./htmlcov.

  Last update : 11.09.2026

Last review : 11.09.2026