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_knn6003503948568997758'
====================================================================
+/tmp/viash_test_knn6003503948568997758/build_executable/knn ---verbosity 6 ---setup cachedbuild
[notice] Building container 'ghcr.io/openproblems-bio/label_projection/methods/knn:test' with Dockerfile
[info] Running 'docker build -t ghcr.io/openproblems-bio/label_projection/methods/knn:test /tmp/viash_test_knn6003503948568997758/build_executable -f /tmp/viash_test_knn6003503948568997758/build_executable/tmp/dockerbuild-knn-yZEqke/Dockerfile'
#0 building with "default" instance using docker driver

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

#2 [internal] load metadata for ghcr.io/openproblems-bio/base_python:1.0.4
#2 DONE 0.2s

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

#4 [1/2] FROM ghcr.io/openproblems-bio/base_python:1.0.4@sha256:e907268bee0b400e0eb1555d9cf6727ac64d976fb097eb669debd686fceaa705
#4 resolve ghcr.io/openproblems-bio/base_python:1.0.4@sha256:e907268bee0b400e0eb1555d9cf6727ac64d976fb097eb669debd686fceaa705 done
#4 sha256:fea1432adf0957427b45b0ef8e37cbfe045b7cf8c15e3f43e48f2f613e214d16 9.44MB / 49.58MB 0.1s
#4 sha256:3873416e6a335157d669c6193a256dfb289331d669d87f200e4eed1f19f9ebb9 0B / 64.14MB 0.1s
#4 sha256:5651b5803b186603909f6c77cdff7bdd4ba7ab8ca4ebccb5a6b0be9037b4e5b6 0B / 24.05MB 0.1s
#4 sha256:e907268bee0b400e0eb1555d9cf6727ac64d976fb097eb669debd686fceaa705 2.43kB / 2.43kB done
#4 sha256:a3b0ed836261f4a7fc6984bb2a57f6cf056c33572743304a2db573317dd7f61d 9.42kB / 9.42kB done
#4 sha256:fea1432adf0957427b45b0ef8e37cbfe045b7cf8c15e3f43e48f2f613e214d16 49.58MB / 49.58MB 0.3s
#4 sha256:3873416e6a335157d669c6193a256dfb289331d669d87f200e4eed1f19f9ebb9 60.06MB / 64.14MB 0.3s
#4 sha256:5651b5803b186603909f6c77cdff7bdd4ba7ab8ca4ebccb5a6b0be9037b4e5b6 24.05MB / 24.05MB 0.3s
#4 sha256:fea1432adf0957427b45b0ef8e37cbfe045b7cf8c15e3f43e48f2f613e214d16 49.58MB / 49.58MB 0.3s done
#4 sha256:3873416e6a335157d669c6193a256dfb289331d669d87f200e4eed1f19f9ebb9 64.14MB / 64.14MB 0.4s
#4 sha256:5651b5803b186603909f6c77cdff7bdd4ba7ab8ca4ebccb5a6b0be9037b4e5b6 24.05MB / 24.05MB 0.3s done
#4 sha256:8a142b8b0e695954ed154c13c098ede4e217dcb99aa7158e34361604191822bd 4.19MB / 211.21MB 0.4s
#4 sha256:c1ab5c0b7cabbec24848a07baf1bd993a7b514f6fc50c28b4f0eb895406f4d1f 2.52MB / 6.39MB 0.4s
#4 sha256:3873416e6a335157d669c6193a256dfb289331d669d87f200e4eed1f19f9ebb9 64.14MB / 64.14MB 0.4s done
#4 sha256:c1ab5c0b7cabbec24848a07baf1bd993a7b514f6fc50c28b4f0eb895406f4d1f 6.39MB / 6.39MB 0.4s done
#4 extracting sha256:fea1432adf0957427b45b0ef8e37cbfe045b7cf8c15e3f43e48f2f613e214d16 0.1s
#4 sha256:678de705bd83053003d0d7df78054a597bf3b083c55090876a4ddaef4b581163 0B / 19.84MB 0.5s
#4 sha256:a394990b4bc6f4c79bf6ee665dd216e441dc33e3f5e120982897790bdd5f89c5 243B / 243B 0.5s done
#4 sha256:40934de00645f8cfc0e25fd1aa4fdb48582214b242fd95de31a31017cbdf337b 0B / 3.13MB 0.5s
#4 sha256:678de705bd83053003d0d7df78054a597bf3b083c55090876a4ddaef4b581163 8.39MB / 19.84MB 0.6s
#4 sha256:40934de00645f8cfc0e25fd1aa4fdb48582214b242fd95de31a31017cbdf337b 3.13MB / 3.13MB 0.6s
#4 sha256:8a142b8b0e695954ed154c13c098ede4e217dcb99aa7158e34361604191822bd 34.20MB / 211.21MB 0.7s
#4 sha256:678de705bd83053003d0d7df78054a597bf3b083c55090876a4ddaef4b581163 19.84MB / 19.84MB 0.7s
#4 sha256:40934de00645f8cfc0e25fd1aa4fdb48582214b242fd95de31a31017cbdf337b 3.13MB / 3.13MB 0.6s done
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 0B / 237.08MB 0.7s
#4 sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1 32B / 32B 0.6s done
#4 sha256:8a142b8b0e695954ed154c13c098ede4e217dcb99aa7158e34361604191822bd 68.16MB / 211.21MB 0.8s
#4 sha256:678de705bd83053003d0d7df78054a597bf3b083c55090876a4ddaef4b581163 19.84MB / 19.84MB 0.7s done
#4 sha256:8a142b8b0e695954ed154c13c098ede4e217dcb99aa7158e34361604191822bd 137.28MB / 211.21MB 1.0s
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 33.55MB / 237.08MB 1.0s
#4 sha256:8a142b8b0e695954ed154c13c098ede4e217dcb99aa7158e34361604191822bd 170.92MB / 211.21MB 1.1s
#4 sha256:8a142b8b0e695954ed154c13c098ede4e217dcb99aa7158e34361604191822bd 205.64MB / 211.21MB 1.2s
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 52.43MB / 237.08MB 1.2s
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 70.51MB / 237.08MB 1.3s
#4 sha256:8a142b8b0e695954ed154c13c098ede4e217dcb99aa7158e34361604191822bd 211.21MB / 211.21MB 1.5s done
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 114.29MB / 237.08MB 1.6s
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 132.12MB / 237.08MB 1.7s
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 150.99MB / 237.08MB 1.8s
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 167.77MB / 237.08MB 1.9s
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 184.55MB / 237.08MB 2.1s
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 202.38MB / 237.08MB 2.2s
#4 extracting sha256:fea1432adf0957427b45b0ef8e37cbfe045b7cf8c15e3f43e48f2f613e214d16 1.9s done
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 218.10MB / 237.08MB 2.3s
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 230.69MB / 237.08MB 2.5s
#4 extracting sha256:5651b5803b186603909f6c77cdff7bdd4ba7ab8ca4ebccb5a6b0be9037b4e5b6
#4 sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 237.08MB / 237.08MB 2.9s done
#4 extracting sha256:5651b5803b186603909f6c77cdff7bdd4ba7ab8ca4ebccb5a6b0be9037b4e5b6 0.5s done
#4 extracting sha256:3873416e6a335157d669c6193a256dfb289331d669d87f200e4eed1f19f9ebb9
#4 extracting sha256:3873416e6a335157d669c6193a256dfb289331d669d87f200e4eed1f19f9ebb9 2.0s done
#4 extracting sha256:8a142b8b0e695954ed154c13c098ede4e217dcb99aa7158e34361604191822bd
#4 extracting sha256:8a142b8b0e695954ed154c13c098ede4e217dcb99aa7158e34361604191822bd 5.0s done
#4 extracting sha256:c1ab5c0b7cabbec24848a07baf1bd993a7b514f6fc50c28b4f0eb895406f4d1f
#4 extracting sha256:c1ab5c0b7cabbec24848a07baf1bd993a7b514f6fc50c28b4f0eb895406f4d1f 0.2s done
#4 extracting sha256:678de705bd83053003d0d7df78054a597bf3b083c55090876a4ddaef4b581163 0.1s
#4 extracting sha256:678de705bd83053003d0d7df78054a597bf3b083c55090876a4ddaef4b581163 0.4s done
#4 extracting sha256:a394990b4bc6f4c79bf6ee665dd216e441dc33e3f5e120982897790bdd5f89c5 done
#4 extracting sha256:40934de00645f8cfc0e25fd1aa4fdb48582214b242fd95de31a31017cbdf337b 0.1s
#4 extracting sha256:40934de00645f8cfc0e25fd1aa4fdb48582214b242fd95de31a31017cbdf337b 0.2s done
#4 extracting sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1 done
#4 extracting sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 0.1s
#4 extracting sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 5.2s
#4 extracting sha256:3c3505c21d5bc23628e864fb99be15bfb4d7048a83afb779ffa09c2ff82ad74e 7.3s done
#4 DONE 21.6s

#5 [2/2] RUN pip install --upgrade pip &&   pip install --upgrade --no-cache-dir "scikit-learn" "jsonschema"
#5 0.497 Requirement already satisfied: pip in /usr/local/lib/python3.11/site-packages (24.1)
#5 0.587 Collecting pip
#5 0.612   Downloading pip-24.2-py3-none-any.whl.metadata (3.6 kB)
#5 0.629 Downloading pip-24.2-py3-none-any.whl (1.8 MB)
#5 0.683    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 41.4 MB/s eta 0:00:00
#5 0.795 Installing collected packages: pip
#5 0.795   Attempting uninstall: pip
#5 0.814     Found existing installation: pip 24.1
#5 0.859     Uninstalling pip-24.1:
#5 0.870       Successfully uninstalled pip-24.1
#5 1.627 Successfully installed pip-24.2
#5 1.628 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.
#5 2.045 Requirement already satisfied: scikit-learn in /usr/local/lib/python3.11/site-packages (1.5.0)
#5 2.165 Collecting scikit-learn
#5 2.197   Downloading scikit_learn-1.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (12 kB)
#5 2.205 Requirement already satisfied: jsonschema in /usr/local/lib/python3.11/site-packages (4.22.0)
#5 2.229 Collecting jsonschema
#5 2.232   Downloading jsonschema-4.23.0-py3-none-any.whl.metadata (7.9 kB)
#5 2.236 Requirement already satisfied: numpy>=1.19.5 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (2.0.0)
#5 2.236 Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (1.13.1)
#5 2.237 Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (1.4.2)
#5 2.237 Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.11/site-packages (from scikit-learn) (3.5.0)
#5 2.238 Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.11/site-packages (from jsonschema) (23.2.0)
#5 2.239 Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.11/site-packages (from jsonschema) (2023.12.1)
#5 2.239 Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.11/site-packages (from jsonschema) (0.35.1)
#5 2.240 Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.11/site-packages (from jsonschema) (0.18.1)
#5 2.259 Downloading scikit_learn-1.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB)
#5 2.326    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.3/13.3 MB 257.2 MB/s eta 0:00:00
#5 2.329 Downloading jsonschema-4.23.0-py3-none-any.whl (88 kB)
#5 2.413 Installing collected packages: scikit-learn, jsonschema
#5 2.413   Attempting uninstall: scikit-learn
#5 2.416     Found existing installation: scikit-learn 1.5.0
#5 2.488     Uninstalling scikit-learn-1.5.0:
#5 2.499       Successfully uninstalled scikit-learn-1.5.0
#5 4.154   Attempting uninstall: jsonschema
#5 4.157     Found existing installation: jsonschema 4.22.0
#5 4.163     Uninstalling jsonschema-4.22.0:
#5 4.166       Successfully uninstalled jsonschema-4.22.0
#5 4.234 Successfully installed jsonschema-4.23.0 scikit-learn-1.5.1
#5 4.234 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.
#5 DONE 4.5s

#6 exporting to image
#6 exporting layers
#6 exporting layers 2.2s done
#6 writing image sha256:1c9c9aa7af6fd089e069f54880d8162d26bdd4cc76dfbcc8fdc1d5ed3ea7738d done
#6 naming to ghcr.io/openproblems-bio/label_projection/methods/knn:test done
#6 DONE 2.2s
====================================================================
+/tmp/viash_test_knn6003503948568997758/test_check_method_config/test_executable
Load config data
Check general fields
Check info fields
Check platform fields
All checks succeeded!
====================================================================
+/tmp/viash_test_knn6003503948568997758/test_run_and_check_adata/test_executable
>> Running test 'run'
>> Checking whether input files exist
>> Running script as test
Load input data
Fit to train data
Predict on test data
Write output to file
>> Checking whether output file exists
>> Reading h5ad files and checking formats
Reading and checking input_train
  AnnData object with n_obs × n_vars = 387 × 1500
    obs: 'label', 'batch'
    var: 'hvg', 'hvg_score'
    uns: 'dataset_id', 'normalization_id'
    obsm: 'X_pca'
    layers: 'counts', 'normalized'
Reading and checking input_test
  AnnData object with n_obs × n_vars = 213 × 1500
    obs: 'batch'
    var: 'hvg', 'hvg_score'
    uns: 'dataset_id', 'normalization_id'
    obsm: 'X_pca'
    layers: 'counts', 'normalized'
Reading and checking output
  AnnData object with n_obs × n_vars = 213 × 1500
    obs: 'batch', 'label_pred'
    var: 'hvg', 'hvg_score'
    uns: 'dataset_id', 'method_id', 'normalization_id'
    obsm: 'X_pca'
    layers: 'counts', 'normalized'
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 --query label_projection --parallel --platform docker
Output
            namespace        functionality             platform            test_name exit_code duration               result
label_projection/methods  logistic_regression               docker                start                                        
label_projection/methods               scanvi               docker                start                                        
label_projection/methods                  knn               docker                start                                        
label_projection/methods                  mlp               docker                start                                        
label_projection/metrics             accuracy               docker                start                                        
label_projection/metrics                   f1               docker                start
label_projection/methods  logistic_regression               docker     build_executable         0        4              SUCCESS
label_projection/methods  logistic_regression               docker      generic_test.py         0        9              SUCCESS
label_projection/metrics                   f1               docker     build_executable         0        7              SUCCESS
label_projection/metrics                   f1               docker      format_check.py         0        8              SUCCESS
label_projection/metrics             accuracy               docker     build_executable         0        8              SUCCESS
label_projection/metrics             accuracy               docker      format_check.py         0        7              SUCCESS
...

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 ...