Run tests

Run unit tests for a component

A component in OpenProblems will typically come with at least two unit tests out of the box:

Use viash test to run all of the component’s unit tests.

Example

viash test src/tasks/label_projection/methods/knn/config.vsh.yaml
Output
Running tests in temporary directory: '/tmp/viash_test_logistic_regression_4853573079508529415'
====================================================================
+/tmp/viash_test_logistic_regression_4853573079508529415/build_engine_environment/logistic_regression ---verbosity 6 ---setup cachedbuild ---engine docker
[notice] Building container 'ghcr.io/openproblems-bio/task_template/methods/logistic_regression:test' with Dockerfile
[info] docker build -t 'ghcr.io/openproblems-bio/task_template/methods/logistic_regression:test'  '/tmp/viash_test_logistic_regression_4853573079508529415/build_engine_environment' -f '/tmp/viash_test_logistic_regression_4853573079508529415/build_engine_environment/tmp/dockerbuild-logistic_regression-D1ntB3/Dockerfile'
#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 571B done
#1 DONE 0.0s

#2 [auth] openproblems/base_python:pull token for registry-1.docker.io
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/openproblems/base_python:1.0.0
#3 DONE 0.3s

#4 [internal] load .dockerignore
#4 transferring context: 2B done
#4 DONE 0.0s

#5 [1/2] FROM docker.io/openproblems/base_python:1.0.0@sha256:bbb0a093e275498bf905237c8cd26124d436f5d35d0f8dd1749c06d0a0a2e88c
#5 resolve docker.io/openproblems/base_python:1.0.0@sha256:bbb0a093e275498bf905237c8cd26124d436f5d35d0f8dd1749c06d0a0a2e88c done
#5 sha256:f3113a160ebb790d7b7e5c9a2148c422ca3f71d30ab661b05c922da5923e4672 9.52kB / 9.52kB done
#5 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 0B / 24.05MB 0.1s
#5 sha256:bbb0a093e275498bf905237c8cd26124d436f5d35d0f8dd1749c06d0a0a2e88c 2.43kB / 2.43kB done
#5 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 0B / 49.56MB 0.1s
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 2.10MB / 64.15MB 0.1s
#5 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 10.49MB / 24.05MB 0.2s
#5 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 15.73MB / 49.56MB 0.2s
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 12.58MB / 64.15MB 0.2s
#5 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 23.07MB / 24.05MB 0.3s
#5 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 25.17MB / 49.56MB 0.3s
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 23.07MB / 64.15MB 0.3s
#5 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 24.05MB / 24.05MB 0.4s done
#5 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 39.85MB / 49.56MB 0.4s
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 52.43MB / 64.15MB 0.5s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 19.92MB / 211.27MB 0.5s
#5 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 49.56MB / 49.56MB 0.6s done
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 64.15MB / 64.15MB 0.6s done
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 56.62MB / 211.27MB 0.7s
#5 extracting sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913
#5 sha256:a0ff605e08b8c97d64efd5de9004f7be648fe6181093227246142e70eda4d985 6.16MB / 6.16MB 0.7s done
#5 sha256:a040235ac426a0e27ffff8201c375bc2dea5e9b79fbe3de107e8640a3152cb3a 5.24MB / 19.84MB 0.7s
#5 sha256:bf8c0a4030de5f4f6d52f2fd8d70281f7230aa557d51632f7fb27f5c7bca0720 0B / 232B 0.7s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 69.15MB / 211.27MB 0.8s
#5 sha256:a040235ac426a0e27ffff8201c375bc2dea5e9b79fbe3de107e8640a3152cb3a 19.84MB / 19.84MB 0.8s done
#5 sha256:bf8c0a4030de5f4f6d52f2fd8d70281f7230aa557d51632f7fb27f5c7bca0720 232B / 232B 0.7s done
#5 sha256:608bb063c2b69dbab463e8ba089f65d9ca171add34cc5dc77434d44320dc4858 3.13MB / 3.13MB 0.8s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 82.84MB / 211.27MB 0.9s
#5 sha256:608bb063c2b69dbab463e8ba089f65d9ca171add34cc5dc77434d44320dc4858 3.13MB / 3.13MB 0.8s done
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 5.24MB / 239.90MB 0.9s
#5 sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1 32B / 32B 0.9s done
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 112.20MB / 211.27MB 1.1s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 22.02MB / 239.90MB 1.1s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 42.49MB / 239.90MB 1.2s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 135.27MB / 211.27MB 1.3s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 61.87MB / 239.90MB 1.3s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 79.62MB / 239.90MB 1.5s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 148.90MB / 211.27MB 1.6s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 96.47MB / 239.90MB 1.7s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 174.06MB / 211.27MB 1.9s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 125.83MB / 239.90MB 1.9s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 144.29MB / 239.90MB 2.0s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 203.42MB / 211.27MB 2.2s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 177.21MB / 239.90MB 2.2s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 192.94MB / 239.90MB 2.3s
#5 extracting sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 1.9s done
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 209.72MB / 239.90MB 2.4s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 229.64MB / 239.90MB 2.6s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 211.27MB / 211.27MB 2.6s done
#5 extracting sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 0.1s
#5 sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 239.90MB / 239.90MB 3.2s done
#5 extracting sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 0.9s done
#5 extracting sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2
#5 extracting sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 2.1s done
#5 extracting sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81
#5 extracting sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 5.1s
#5 extracting sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 5.2s done
#5 extracting sha256:a0ff605e08b8c97d64efd5de9004f7be648fe6181093227246142e70eda4d985
#5 extracting sha256:a0ff605e08b8c97d64efd5de9004f7be648fe6181093227246142e70eda4d985 0.2s done
#5 extracting sha256:a040235ac426a0e27ffff8201c375bc2dea5e9b79fbe3de107e8640a3152cb3a 0.1s
#5 extracting sha256:a040235ac426a0e27ffff8201c375bc2dea5e9b79fbe3de107e8640a3152cb3a 0.4s done
#5 extracting sha256:bf8c0a4030de5f4f6d52f2fd8d70281f7230aa557d51632f7fb27f5c7bca0720 done
#5 extracting sha256:608bb063c2b69dbab463e8ba089f65d9ca171add34cc5dc77434d44320dc4858
#5 extracting sha256:608bb063c2b69dbab463e8ba089f65d9ca171add34cc5dc77434d44320dc4858 0.2s done
#5 extracting sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1 done
#5 extracting sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 0.1s
#5 extracting sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 5.2s
#5 extracting sha256:2ab4a9a4417c3cba6da0695fbcb161acd24bd950f468b0c807bf365f4c09dfc2 7.7s done
#5 DONE 21.6s

#6 [2/2] RUN pip install --upgrade pip &&   pip install --upgrade --no-cache-dir "scikit-learn"
#6 0.635 Requirement already satisfied: pip in /usr/local/lib/python3.11/site-packages (24.2)
#6 0.833 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.
#6 1.261 Requirement already satisfied: scikit-learn in /usr/local/lib/python3.11/site-packages (1.5.1)
#6 1.419 Requirement already satisfied: numpy>=1.19.5 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (1.26.4)
#6 1.420 Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (1.14.1)
#6 1.420 Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (1.4.2)
#6 1.421 Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (3.5.0)
#6 1.503 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.
#6 DONE 1.8s

#7 exporting to image
#7 exporting layers
#7 exporting layers 2.1s done
#7 writing image sha256:e2a8019a842729393ab11d5907f38f97f24c7a6f292a819eed3e1083523809aa done
#7 naming to ghcr.io/openproblems-bio/task_template/methods/logistic_regression:test done
#7 DONE 2.1s
====================================================================
+/tmp/viash_test_logistic_regression_4853573079508529415/test_run_and_check_output/test_executable
>> Running test 'run'
>> Checking whether input files exist
>> Running script as test
Reading input files
Preprocess data
Train model
Generate predictions
Write output AnnData to file
>> Checking whether output file exists
>> Reading h5ad files and checking formats
Reading and checking output
  AnnData object with n_obs × n_vars = 213 × 0
    obs: 'label_pred'
    uns: 'dataset_id', 'method_id', 'normalization_id'
All checks succeeded!
====================================================================
+/tmp/viash_test_logistic_regression_4853573079508529415/test_check_config/test_executable
Load config data
Check .namespace
Check .info.type
Check component metadata
Check references fields
Checking contents of .info.preferred_normalization
Check Nextflow runner
All checks succeeded!
====================================================================
SUCCESS! All 2 out of 2 test scripts succeeded!
Cleaning up temporary directory

Test multiple components

Use viash ns test to unit test all of the components of a given task.

viash ns test --parallel
Output
    namespace                 name               runner               engine            test_name exit_code duration               result
control_methods          true_labels           executable               docker                start                                        
        metrics             accuracy           executable               docker                start                                        
data_processors      process_dataset           executable               docker                start                                        
        methods  logistic_regression           executable               docker                start                                        
data_processors      process_dataset           executable               docker     build_executable         0        2              SUCCESS
data_processors      process_dataset           executable               docker run_and_check_output.py         0        4              SUCCESS
control_methods          true_labels           executable               docker     build_executable         0        2              SUCCESS
control_methods          true_labels           executable               docker run_and_check_output.py         0        4              SUCCESS
control_methods          true_labels           executable               docker      check_config.py         0        3              SUCCESS
        metrics             accuracy           executable               docker     build_executable         0        2              SUCCESS
        metrics             accuracy           executable               docker run_and_check_output.py         0        5              SUCCESS
        metrics             accuracy           executable               docker      check_config.py         0        2              SUCCESS
        methods  logistic_regression           executable               docker     build_executable         0        2              SUCCESS
        methods  logistic_regression           executable               docker run_and_check_output.py         0        5              SUCCESS
        methods  logistic_regression           executable               docker      check_config.py         0        3              SUCCESS
All 11 configs built and tested successfully …

Common errors

Below is a listing of common errors and how to solve them. If you come across any other problems, please take a look at our troubleshooting page, or reach out via GitHub issues.

Assertion error

An assertion error typically occurs when data format of input or output parameters is incorrect.

Component script errors:

  • Output file cannot be found: Check that your script writes to the correct output filename.

  • Some fields/objects cannot be found in the output file: Check whether the correct fields are written in the output file.

+/tmp/viash_test_knn12471306149427017048/test_generic_test/test_executable
>> Running script as test
>> Checking whether output file exists
>> Reading h5ad files
>> Checking whether predictions were added
Traceback (most recent call last):
  File "/viash_automount/tmp/viash_test_knn12471306149427017048/test_generic_test/tmp//viash-run-knn-QTKmUM.py", line 57, in <module>
    assert "label_predi" in output.obs
AssertionError

Component config errors:

When these AssertionErrors occur, check the spelling of the missing value if it is present in the file. If the field is irrelevant you can simply add an empty string "" to make sure it is included in the composed config file.

+/tmp/viash_test_knn12945373156205296243/test_check_method_config/test_executable
Load config data
check general fields
Traceback (most recent call last):
Check info fields
  File "/viash_automount/tmp/viash_test_knn12945373156205296243/test_check_method_config/tmp//viash-run-knn-Xn2Vd7.py", line 42, in <module>
    assert "summary" in info is not None, "summary not an info field or is empty"
AssertionError: summary not an info field or is empty

Python / R dependency does not exist

When a dependency for the unit test or the executed script is not added to the setup of the docker you will get a ModuleNotFoundError. Add the dependency to the setup.

ModuleNotFoundError: No module named 'yaml'

Docker image not found

When this kind of error occurs make sure there are no spelling mistakes in the image name.

#3 ERROR: docker.io/library/python:3.1: not found
------
> [internal] load metadata for docker.io/library/python:3.1:
------
Dockerfile:1
--------------------
  1 | >>> FROM python:3.1
  2 |     
  3 |     RUN pip install --upgrade pip && \
--------------------
ERROR: failed to solve: python:3.1: docker.io/library/python:3.1: not found
[error] Error occurred while building container 'ghcr.io/openproblems-bio/label_projection/methods/knn:test'
ERROR! Setup failed!

Script error

When the executed script has an error it will be printed out like the example below. In most cases you can find the problem in the stack trace.

+/tmp/viash_test_knn14797416935521308344/test_generic_test/test_executable
>> Running script as test
Load input data
Traceback (most recent call last):
File "/tmp/viash-run-knn-p4pvkA.py", line 31, in <module>
  input_test = ad.read_h5ad(par['input_test'])
File "/usr/local/lib/python3.10/site-packages/anndata/_io/h5ad.py", line 224, in read_h5ad
  with h5py.File(filename, "r") as f:
File "/usr/local/lib/python3.10/site-packages/h5py/_hl/files.py", line 542, in __init__
  name = filename_encode(name)
File "/usr/local/lib/python3.10/site-packages/h5py/_hl/compat.py", line 19, in filename_encode
  filename = fspath(filename)
TypeError: expected str, bytes or os.PathLike object, not NoneType
Method script with returncode ...