Loading modules in your test environment#
Some tests require a modified environment. When the required environment modifications are contained in module, canary can load the module prior to test execution. There are two ways to modify the environment by loading a module:
Through the
canary.module.loadedcontext manager:import canary def test(): with canary.module.loaded("modulename"): # do work
To add the module’s path to
MODULEPATHdef test(): with canary.module.loaded("modulename", use="modulepath"): # do work
Through the
canary.directives.load()directive:import canary canary.directives.load_module("modulename", use=..., when=...) def test(): # do work