Copying and linking resource files into the test execution directory#

Resources needed by tests can be copied and linked from their source locations to the execution directory with the canary.directives.copy() and canary.directives.link() directives, respectively, as shown in the following example:

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

import os

import canary

canary.directives.copy("copy.txt")
canary.directives.link("link.txt")


def test():
    assert os.path.exists("copy.txt") and not os.path.islink("copy.txt")
    assert os.path.exists("link.txt") and os.path.islink("link.txt")
$ canary run ./copy_and_link
...
$ cd $(canary location copy_and_link); ls -l *.txt
-rw-r--r-- 1 docs docs 1608 Apr 21 15:34 canary-out.txt
-rw-r--r-- 1 docs docs    0 Apr 21 15:34 copy.txt
lrwxrwxrwx 1 docs docs  127 Apr 21 15:34 link.txt -> /home/docs/checkouts/readthedocs.org/user_builds/canary-wm/checkouts/release-26.4.16/src/canary/examples/copy_and_link/link.txt