Common Workflow Language testing framework
This is a testing tool for checking the output of Tools and Workflows described with the Common Workflow Language. Among other uses, it is used to run the CWL conformance tests.
This is written and tested for Python 3.8, 3.9, 3.10, 3.11, and 3.12.
Install
Installing the official package from PyPi
pip install cwltest
Or from bioconda
conda install -c bioconda cwltest
Or from source
git clone https://github.com/common-workflow-language/cwltest.git
cd cwltest && pip install .
Run on the command line
Simple command:
cwltest --test test-descriptions.yml --tool cwl-runner
Generate conformance badges using cwltest
To make badges that show the results of the conformance test, you can generate JSON files for https://badgen.net by using –badgedir option
To generate JSON files:
cwltest --test test-descriptions.yml --tool cwl-runner --badgedir badges
...
$ cat badges/command_line_tool.json | jq .
{
"subject": "command_line_tool",
"status": "100%",
"color": "green"
}
Once you upload JSON file to a server, you make a badge by using a link like https://badgen.net/https/path/to/generated/json or https://flat.badgen.net/https/path/to/generated/json (for flat badges).
Here is an example of markdown to add a badge:

Command Line Options
cwltest
Common Workflow Language testing framework
usage: cwltest [-h] --test TEST [--basedir BASEDIR] [-l] [-n N] [-s S] [-N N]
[-S S] [--tool TOOL] [--only-tools] [--tags TAGS]
[--exclude-tags EXCLUDE_TAGS] [--show-tags]
[--junit-xml JUNIT_XML] [--junit-verbose]
[--test-arg cache==--cache-dir] [-j J] [--verbose]
[--classname CLASSNAME] [--timeout TIMEOUT]
[--badgedir BADGEDIR] [--version]
...
- args
arguments to pass first to tool runner
- -h, --help
show this help message and exit
- --test <test>
YAML file describing test cases
- --basedir <basedir>
Basedir to use for tests
- -l
List tests then exit
- -n <n>
Run specific tests, format is 1,3-6,9
- -s <s>
Run specific tests using their short names separated by comma
- -N <n>
Exclude specific tests by number, format is 1,3-6,9
- -S <s>
Exclude specific tests by short names separated by comma
- --tool <tool>
CWL runner executable to use (default ‘cwl-runner’
- --only-tools
Only test CommandLineTools
- --tags <tags>
Tags to be tested
- --exclude-tags <exclude_tags>
Tags not to be tested
- --show-tags
Show all Tags.
- --junit-xml <junit_xml>
Path to JUnit xml file
- --junit-verbose
Store more verbose output to JUnit XML file by not passing ‘–quiet’ to the CWL runner.
- --test-arg <cache==--cache-dir>
Additional argument given in test cases and required prefix for tool runner.
- -j <j>
Specifies the number of tests to run simultaneously (defaults to one).
- --verbose
More verbose output during test run.
- --classname <classname>
Specify classname for the Test Suite.
- --timeout <timeout>
Time of execution in seconds after which the test will be skipped. Defaults to 600 seconds (10.0 minutes).
- --badgedir <badgedir>
Create JSON badges and store them in this directory.
- --version
show program’s version number and exit
Pytest plugin
cwltest
can also be used as a Pytest 7.x or 8.x plugin. The CWL test
filename must end with .cwltest.yml
or .cwltest.yaml
.
In this case, the simple command:
cwltest --test conformance_xxx.cwltest.yml --tool cwl-runner
becomes:
pytest conformance_xxx.cwltest.yml --cwl-runner cwl-runner
Command Line Options
pytest
usage: pytest [--cwl-runner CWL_RUNNER] [--cwl-runner-verbose]
[--cwl-badgedir CWL_BADGEDIR] [--cwl-include CWL_INCLUDE]
[--cwl-exclude CWL_EXCLUDE] [--cwl-tags CWL_TAGS]
[--cwl-exclude-tags CWL_EXCLUDE_TAGS] [--cwl-args CWL_ARGS]
[--cwl-test-arg CWL_TEST_ARG] [--cwl-basedir CWL_BASEDIR]
- --cwl-runner <cwl_runner>
Name of the CWL runner to use.
- --cwl-runner-verbose
If set, don’t pass –quiet to the CWL runner.
- --cwl-badgedir <cwl_badgedir>
Create badge JSON files and store them in this directory.
- --cwl-include <cwl_include>
Run specific CWL tests using their short names separated by comma
- --cwl-exclude <cwl_exclude>
Exclude specific CWL tests using their short names separated by comma
- --cwl-tags <cwl_tags>
Tags to be tested.
- --cwl-exclude-tags <cwl_exclude_tags>
Tags not to be tested.
- --cwl-args <cwl_args>
one or more arguments to pass first to tool runner (separated by spaces)
- --cwl-test-arg <cwl_test_arg>
Additional argument given in test cases and required prefix for tool runner.
- --cwl-basedir <cwl_basedir>
Basedir to use for tests
Converting cwltest
options to pytest
options
The table below details all the available command conversions between the two formats.
Feature |
|
|
---|---|---|
YAML file describing test cases |
|
|
CWL runner executable to use |
|
|
Specifies the number of tests to run simultaneously |
|
|
Automatically scale the number of tests to run simultaneously |
UNSUPPORTED |
|
Only run one test at a time (good for debugging cwltest itself) |
(or leave out |
|
Time of execution in seconds after which the test will be skipped |
|
|
List tests then exit |
|
|
Run specific tests using their short names |
|
|
Exclude specific tests by short names |
|
|
Tags to be tested |
|
|
Tags not to be tested |
|
|
Path to JUnit xml file |
|
|
More verbose output during test run |
|
|
Additional argument given in test cases and required prefix for tool runner |
|
|
Arguments to pass first to tool runner |
|
|
Only test CommandLineTools |
|
UNSUPPORTED |
Show all tags |
|
UNSUPPORTED |
Store more verbose output to JUnit xml file |
|
|
Specify classname for the Test Suite |
|
UNSUPPORTED |
Differences in the XML output
cwltest --junit-xml
output
top-level
<testsuites>
element has the elapsed time, and counts (errors, failures, skipped, and total)singular
<testsuite>
sub-element the same attributes as the top-level<testsuites>
plusname
which is the basename of the YAML test fileeach
<testcase>
element has the follow attributesname
: the doc stringclass
: the tagsfile
: the test IDurl
: like “cwltest:conformance_tests#1” (contains the basename of the YAML test file)time
: the elapsed time
<testcase>
elements always contain the following sub-elements, regardless of outcome<system-out>
: the output object<system-err>
: stderr (docker pull, other warnings, and errors)
<testcase>
elements for failed test cases do not have a<failure>
sub-element
pytest
with cwltest
plugin XML output
top-level
<testsuites>
element has no attributessingular
<testsuite>
sub-element has the same attributes as thecwltest
XML version along with these additional attributesname
: default ispytest
(can be customized with the pytest INI optionjunit_suite_name
)timestamp="2023-01-08T11:39:07.425159"
hostname
: the hostname of the machine where the tests ran
inside the
<testsuite>
is a<properties>..</properties>
element with two<property name="…" value="…" />
elements. But this does not work with pytest-xdist.runner
: the name of the CWL runnerrunner_extra_args
: the value of –cwl-args`
each
<testcase>
element has the following attributesclassname
: always the name of the YAML file (conformance_test_v1.2.cwltest.yaml
)name
: the test IDtime
: the elapsed time
<testcase>
elements for failed test cases do have a<failure>
sub-element with amessage
attribute containing thecwltest.plugin.CWLItem.repr_failure()
output. This text is repeated as the content of the<failure>
element. The presensce of<system-out>
and<system-err>
sub-elements varies. [4]
[4] (1,2,3) Depending on the value of the pytest INI option
junit_logging
, then<system-out>
and<system-err>
sub-elements will be generated. However the default value forjunit_logging
isno
, so to get either of these pick one from the full list. You can setjunit_logging
in a configuration file or on the command line:pytest -o junit_logging=out-err
.
API Reference
This page contains auto-generated API reference documentation [1].
cwltest
Run CWL descriptions with a cwl-runner, and look for expected output.
Submodules
cwltest.__main__
Default entrypoint for the cwltest module.
cwltest.argparser
Command line argument parsing for cwltest.
Module Contents
Functions
Generate a command Line argument parser for cwltest. |
- cwltest.argparser.arg_parser()
Generate a command Line argument parser for cwltest.
- Return type:
cwltest.compare
Compare utilities for CWL objects.
Module Contents
Functions
|
Compare two CWL objects. |
cwltest.hooks
Hooks for pytest-cwl users.
Module Contents
Functions
|
Execute CWL test using a Python function instead of a command line runner. |
- cwltest.hooks.pytest_cwl_execute_test(config, processfile, jobfile)
Execute CWL test using a Python function instead of a command line runner.
- The return value is a tuple.
- status code
0 = success
cwltest.UNSUPPORTED_FEATURE
for an unsupported featureand any other number for failure
CWL output object using plain Python objects.
cwltest.main
Entry point for cwltest.
Module Contents
Functions
|
Run the main logic loop. |
Attributes
- cwltest.main.PREFIX = '\r'
cwltest.plugin
Discovers CWL test files and converts them to pytest.Items.
Module Contents
Classes
Protocol to type-check test runner functions via the pluggy hook. |
|
A CWL test Item. |
|
A CWL test file. |
Functions
|
Add our options to the pytest command line. |
|
Is this file for us. |
|
Store the raw tests and the test results. |
|
Generate badges. |
|
Register our cwl hooks. |
- class cwltest.plugin.TestRunner
Bases:
Protocol
Protocol to type-check test runner functions via the pluggy hook.
- class cwltest.plugin.CWLItem(name, parent, spec)
Bases:
pytest.Item
A CWL test Item.
- runtest()
Execute using cwltest.
- Return type:
None
- repr_failure(excinfo, style=None)
Document failure reason.
Called when self.runtest() raises an exception.
- Parameters:
excinfo (ExceptionInfo[BaseException])
style (Optional[_pytest._code.code._TracebackStyle])
- Return type:
- class cwltest.plugin.CWLYamlFile(fspath=None, path_or_parent=None, path=None, name=None, parent=None, config=None, session=None, nodeid=None)
Bases:
pytest.File
A CWL test file.
- Parameters:
fspath (Optional[_pytest.compat.LEGACY_PATH])
path_or_parent (Optional[Union[pathlib.Path, Node]])
path (Optional[pathlib.Path])
name (Optional[str])
parent (Optional[Node])
config (Optional[_pytest.config.Config])
session (Optional[_pytest.main.Session])
nodeid (Optional[str])
- cwltest.plugin.pytest_addoption(parser)
Add our options to the pytest command line.
- Parameters:
parser (_pytest.config.argparsing.Parser)
- Return type:
None
- cwltest.plugin.pytest_collect_file(file_path, parent)
Is this file for us.
- Parameters:
file_path (pathlib.Path)
parent (pytest.Collector)
- Return type:
Optional[pytest.Collector]
- cwltest.plugin.pytest_configure(config)
Store the raw tests and the test results.
- Parameters:
config (_pytest.config.Config)
- Return type:
None
- cwltest.plugin.pytest_sessionfinish(session, exitstatus)
Generate badges.
- Parameters:
session (pytest.Session)
exitstatus (int)
- Return type:
None
- cwltest.plugin.pytest_addhooks(pluginmanager)
Register our cwl hooks.
- Parameters:
pluginmanager (_pytest.config.PytestPluginManager)
- Return type:
None
cwltest.utils
Package Contents
- cwltest.UNSUPPORTED_FEATURE = 33
- cwltest.DEFAULT_TIMEOUT = 600
- cwltest.REQUIRED = 'required'
- cwltest.logger
- cwltest.templock
Created with sphinx-autoapi