Common Workflow Language Testing Framework (cwltest)

2.6.20251216093331 · active · verified Fri Apr 17

cwltest is the Common Workflow Language (CWL) testing framework. It provides tools to validate CWL workflows against defined test cases. As of its latest version 2.6.20251216093331, it supports Python versions 3.10 to 3.14. The library has a rapid release cadence, often with multiple releases per month, using a date-based versioning scheme.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `cwltest` command-line tool to run tests against a simple CWL workflow. It creates a dummy CWL workflow and a test definition file, then executes `cwltest`. For `cwltest` to actually run the CWL workflow during testing, a CWL runner like `cwltool` must be installed alongside `cwltest`.

import subprocess
import tempfile
from pathlib import Path
import os

# Create a dummy CWL workflow file
cwl_content = """
cwlVersion: v1.0
class: CommandLineTool
baseCommand: echo
inputs:
  message:
    type: string
    inputBinding:
      position: 1
outputs:
  output: 
    type: stdout
stdout: output.txt
"""

# Create a dummy CWL test file
test_content = """
- doc: Example test for echo tool
  tool: workflow.cwl
  job:
    message: Hello, CWL!
  output:
    output: Hello, CWL!\n
- doc: Another test
  tool: workflow.cwl
  job:
    message: Another message
  output:
    output: Another message\n
"""

with tempfile.TemporaryDirectory() as tmpdir:
    tmp_path = Path(tmpdir)
    workflow_path = tmp_path / "workflow.cwl"
    test_path = tmp_path / "test_example.yml"

    workflow_path.write_text(cwl_content)
    test_path.write_text(test_content)

    print(f"Created dummy workflow: {workflow_path}")
    print(f"Created dummy test file: {test_path}")

    print("\nRunning cwltest...")
    try:
        # cwltest uses cwltool by default to execute the workflow
        # Ensure cwltool is installed for this example to fully function:
        # pip install cwltest cwltool
        cmd = ["cwltest", "--test", str(test_path), "--basedir", str(tmp_path)]
        result = subprocess.run(cmd, capture_output=True, text=True, check=True)
        print("cwltest output:")
        print(result.stdout)
        print("Tests passed successfully!")
    except subprocess.CalledProcessError as e:
        print(f"cwltest failed with error: {e}")
        print(f"Stderr: {e.stderr}")
        print(f"Stdout: {e.stdout}")
    except FileNotFoundError:
        print("Error: 'cwltest' command not found. Ensure cwltest is installed and in your PATH.")
        print("Note: You might also need 'cwltool' installed for cwltest to execute CWL workflows.")

view raw JSON →