Testing - reanahub/reana GitHub Wiki
Using separate virtual environments
When working on unit tests for a REANA cluster component, please always use separate terminal window and separate Python virtual environment for each component in order not to mix dependencies.
For example:
cd ~/src/reana-server
mkvirtualenv _reana_server -p python3.12
pip install --upgrade pip
pip install '.[all]' --upgrade --use-feature=fast-deps
cd ~/src/reana-workflow-controller
mkvirtualenv _reana_server -p python3.12
pip install --upgrade pip
pip install '.[all]' --upgrade --use-feature=fast-deps
workon _reana_server
./run-tests.sh
workon _reana_workflow_controller
./run-tests.sh
Running Python unit tests of a component
The run-tests.sh helper command has an option to run only those kind of tests
that you are interested in, for example Python tests:
workon _reana_server
./run-tests.sh --check-pytest
Note that you can use an environment variable PYTEST_ADDOPTS to run only
certain desired tests, for example:
PYTEST_ADDOPTS=tests/test_cli.py ./run-tests.sh --check-pytest
PYTEST_ADDOPTS=tests/test_cli.py::test_export_users ./run-tests.sh --check-pytest
Running all tests for a component
Instead of creating virtual environments manually, you can also use the
reana-dev helper script command to run all the tests for one or more
components automatically. This is mostly useful when reviewing code of a
component without actually working on the implementation or the tests. For
example:
reana-dev python-unit-tests -c r-j-controller -k
The above command will automatically create _reana-job-controller virtual
environment in which the tests will be run. The option -k will optionally
keep the environments after tests are finished for any eventual manual
inspection and editing.
Common testing issues and solutions
Issue: Resource 'api' has no operation 'new_endpoint'
If you encounter the error Resource 'api' has no operation 'new_endpoint'
while running a unit test that involves a new endpoint, follow these steps to
resolve the issue:
-
Ensure that the new endpoint is included in the OpenAPI spec in both
reana-commonsand thereana-commonsmodule inreana-server. -
Reinstall
reana-commonswith editable (-e) mode in your virtual environment:cd reana-commons pip install -e . -
Retry the unit test after reinstalling reana-commons.