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/methods/logistic_regression/config.vsh.yaml
Output
Running tests in temporary directory: '/tmp/viash_test_logistic_regression_1987810516425144040'
====================================================================
+/tmp/viash_test_logistic_regression_1987810516425144040/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_1987810516425144040/build_engine_environment' -f '/tmp/viash_test_logistic_regression_1987810516425144040/build_engine_environment/tmp/dockerbuild-logistic_regression-AXvutj/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 [internal] load metadata for docker.io/openproblems/base_python:1.0.0
#2 ...

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

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

#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:52302746d441804c9eb067b569f8671b68e6ebb3847da83b16e42b9316dcd583
#5 resolve docker.io/openproblems/base_python:1.0.0@sha256:52302746d441804c9eb067b569f8671b68e6ebb3847da83b16e42b9316dcd583 done
#5 sha256:f295e7043d30810d710c7f0b614bcfd665bd386ea37ca48df9f19ca96f5435e6 9.58kB / 9.58kB done
#5 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 0B / 24.05MB 0.1s
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 0B / 64.15MB 0.1s
#5 sha256:52302746d441804c9eb067b569f8671b68e6ebb3847da83b16e42b9316dcd583 2.43kB / 2.43kB done
#5 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 0B / 49.56MB 0.1s
#5 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 22.02MB / 24.05MB 0.3s
#5 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 35.65MB / 49.56MB 0.3s
#5 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 24.05MB / 24.05MB 0.3s done
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 11.53MB / 64.15MB 0.4s
#5 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 49.56MB / 49.56MB 0.4s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 0B / 211.27MB 0.4s
#5 extracting sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 27.26MB / 64.15MB 0.5s
#5 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 49.56MB / 49.56MB 0.4s done
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 12.58MB / 211.27MB 0.5s
#5 sha256:ddcca6e3f42035ac03358d82b13b5be2a118cd4bacb2772f93c9b863acb9927a 0B / 6.16MB 0.5s
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 38.34MB / 64.15MB 0.6s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 31.46MB / 211.27MB 0.6s
#5 sha256:ddcca6e3f42035ac03358d82b13b5be2a118cd4bacb2772f93c9b863acb9927a 6.16MB / 6.16MB 0.6s done
#5 sha256:b138557b3c9168650e12f59c1b94ca139d6856ab2d9c9254d01f092f08c92894 0B / 19.84MB 0.6s
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 49.28MB / 64.15MB 0.7s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 53.23MB / 211.27MB 0.7s
#5 sha256:b138557b3c9168650e12f59c1b94ca139d6856ab2d9c9254d01f092f08c92894 3.15MB / 19.84MB 0.7s
#5 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 64.15MB / 64.15MB 0.9s done
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 82.84MB / 211.27MB 0.9s
#5 sha256:b138557b3c9168650e12f59c1b94ca139d6856ab2d9c9254d01f092f08c92894 19.84MB / 19.84MB 0.9s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 104.86MB / 211.27MB 1.0s
#5 sha256:b138557b3c9168650e12f59c1b94ca139d6856ab2d9c9254d01f092f08c92894 19.84MB / 19.84MB 0.9s done
#5 sha256:40686028595ecbb07f1b3250557eced506227cbf2af14ff8ccaa2eefb8fd303d 0B / 3.13MB 1.0s
#5 sha256:f941e69671672ba68a9d7c8500f25b8e12f5aef94f4ba97c8fba1c5212435813 0B / 232B 1.0s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 146.80MB / 211.27MB 1.2s
#5 sha256:40686028595ecbb07f1b3250557eced506227cbf2af14ff8ccaa2eefb8fd303d 3.13MB / 3.13MB 1.0s done
#5 sha256:f941e69671672ba68a9d7c8500f25b8e12f5aef94f4ba97c8fba1c5212435813 232B / 232B 1.0s done
#5 sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1 32B / 32B 1.1s done
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 9.44MB / 239.92MB 1.2s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 161.40MB / 211.27MB 1.3s
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 28.31MB / 239.92MB 1.3s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 179.31MB / 211.27MB 1.4s
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 46.14MB / 239.92MB 1.4s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 193.99MB / 211.27MB 1.5s
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 68.17MB / 239.92MB 1.5s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 211.27MB / 211.27MB 1.7s
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 110.10MB / 239.92MB 1.7s
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 133.87MB / 239.92MB 1.8s
#5 sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 211.27MB / 211.27MB 1.8s done
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 160.38MB / 239.92MB 1.9s
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 185.58MB / 239.92MB 2.0s
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 225.94MB / 239.92MB 2.2s
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 239.92MB / 239.92MB 2.4s
#5 extracting sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 2.0s done
#5 sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 239.92MB / 239.92MB 2.6s done
#5 extracting sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707
#5 extracting sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 0.5s done
#5 extracting sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2
#5 extracting sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 2.0s done
#5 extracting sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81
#5 extracting sha256:1c8ff076d818ad6b8557e03e10c83657cc716ab287c8380054ff91571c8cae81 5.0s done
#5 extracting sha256:ddcca6e3f42035ac03358d82b13b5be2a118cd4bacb2772f93c9b863acb9927a
#5 extracting sha256:ddcca6e3f42035ac03358d82b13b5be2a118cd4bacb2772f93c9b863acb9927a 0.2s done
#5 extracting sha256:b138557b3c9168650e12f59c1b94ca139d6856ab2d9c9254d01f092f08c92894 0.1s
#5 extracting sha256:b138557b3c9168650e12f59c1b94ca139d6856ab2d9c9254d01f092f08c92894 0.4s done
#5 extracting sha256:f941e69671672ba68a9d7c8500f25b8e12f5aef94f4ba97c8fba1c5212435813 done
#5 extracting sha256:40686028595ecbb07f1b3250557eced506227cbf2af14ff8ccaa2eefb8fd303d
#5 extracting sha256:40686028595ecbb07f1b3250557eced506227cbf2af14ff8ccaa2eefb8fd303d 0.2s done
#5 extracting sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1 done
#5 extracting sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 0.1s
#5 extracting sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 5.2s
#5 extracting sha256:00a8ac675928069c4d8eb19f9ca6cdb4fffae02789e434e04a86ded5fe2c7530 7.4s done
#5 DONE 22.4s

#6 [2/2] RUN pip install --upgrade pip &&   pip install --upgrade --no-cache-dir "scikit-learn"
#6 0.523 Requirement already satisfied: pip in /usr/local/lib/python3.11/site-packages (24.2)
#6 0.685 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.061 Requirement already satisfied: scikit-learn in /usr/local/lib/python3.11/site-packages (1.5.1)
#6 1.187 Requirement already satisfied: numpy>=1.19.5 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (1.26.4)
#6 1.187 Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (1.14.1)
#6 1.188 Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (1.4.2)
#6 1.188 Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (3.5.0)
#6 1.264 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.4s

#7 exporting to image
#7 exporting layers
#7 exporting layers 2.0s done
#7 writing image sha256:b5c797d9c479d210d1d87399702925416cabe74634520a2f4cfc4194a980fd39 done
#7 naming to ghcr.io/openproblems-bio/task_template/methods/logistic_regression:test done
#7 DONE 2.0s
====================================================================
+/tmp/viash_test_logistic_regression_1987810516425144040/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_1987810516425144040/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                                        
    control_methods          true_labels           executable               docker     build_executable         0        1              SUCCESS
    control_methods          true_labels           executable               docker run_and_check_output.py         0        3              SUCCESS
    control_methods          true_labels           executable               docker      check_config.py         0        3              SUCCESS
    data_processors      process_dataset           executable               docker                start                                        
    data_processors      process_dataset           executable               docker     build_executable         0        1              SUCCESS
    data_processors      process_dataset           executable               docker run_and_check_output.py         0        3              SUCCESS
            methods  logistic_regression           executable               docker                start                                        
            methods  logistic_regression           executable               docker     build_executable         0        1              SUCCESS
            methods  logistic_regression           executable               docker run_and_check_output.py         0        3              SUCCESS
            methods  logistic_regression           executable               docker      check_config.py         0        3              SUCCESS
            metrics             accuracy           executable               docker                start                                        
            metrics             accuracy           executable               docker     build_executable         0        1              SUCCESS
            metrics             accuracy           executable               docker run_and_check_output.py         0        3              SUCCESS
            metrics             accuracy           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 ...