Basic test dependencies#

The depends_on() directive designates one test case as dependent on another. Dependent test cases will not run until all of its dependencies run to completion. When the test case is run, it can query the properties of its dependencies by the instance.dependencies attribute.

Example#

# Copyright NTESS. See COPYRIGHT file for details.
#
# SPDX-License-Identifier: MIT

import sys

import canary

canary.directives.depends_on("a")


def depends_on_a():
    instance = canary.get_instance()
    assert len(instance.dependencies) == 1
    assert instance.dependencies[0].name == "a"


if __name__ == "__main__":
    sys.exit(depends_on_a())

depends_on_a will not run until after a runs:

$ canary run ./depends_on/basic
INFO: Initializing empty canary workspace at .
INFO: Collecting generator files from depends_on/basic
INFO: Instantiating generators from collected files
INFO: Generating test specs from generators
INFO: Searching for duplicated tests
INFO: Resolving test spec dependencies
INFO: Generated 2 test specs from 2 generators
INFO: Caching test specs
INFO: Created selection 'seafoam-otter'
INFO: Selecting test cases based on runtime environment
INFO: Starting session 2026-04-21T15-34-25.520275
INFO: Starting process pool with max 2 workers
Job           ID        Status                                           Queued   Elapsed      Rank  
───────────────────────────────────────────────────────────────────────────────────────────────────
a             387ff3d   SUBMITTED                                                               1/2  
a             387ff3d   STARTED                                            0.3s                 1/2  
a             387ff3d   PASS (SUCCESS)                                     0.3s      0.4s       1/2  
depends_on_a  0a14903   SUBMITTED                                                               2/2  
depends_on_a  0a14903   STARTED                                            0.0s                 2/2  
depends_on_a  0a14903   PASS (SUCCESS)                                     0.0s      0.2s       2/2  
INFO: 2/2 tests finished with status PASS
INFO: Finished session in 0.68 s. with returncode 0
INFO: Updating view at /home/docs/checkouts/readthedocs.org/user_builds/canary-wm/checkouts/release-26.4.16/src/canary/examples/TestResults