Loading tests
Loading Tests
Using load()
You can use load() function to load a test or any object from another module.
For example, given a Scenario defined in tests/another_module.py
1 | from testflows.core import * |
then, using load() function you can load this test in another module and use it as a base test for an inline defined Scenario as follows.
1 | with Module("my module"): |
Using loads()
You can use loads() function to load one or more tests of a given test class.
1 | loads(name, *types, package=None, frame=None, filter=None) |
where
namemodule name or module*typestest types (Step, Test, Scenario, Suite, Feature, or Module), default: allpackagepackage name if module name is relative (optional)framecaller frame if module name is not specified (optional)filterfilter function (optional)
and returns list of tests.
For example, given multiple Scenarios defined in the same file, one can
use loads() function to execute all the Scenarios as follows
1 |
|
If a file contains multiple test types, then you can just specify them as needed. For example,
1 |
|
See also using current_module().
Using ordered()
By default, loads() function returns tests in random order. If you want a deterministic order, then use ordered() function to sort a list of tests loaded with loads() function by test function name.
For example,
1 |
|
Loading Modules
Using current_module()
Using current_module() function allows you to conveniently reference the current module. For example,
1 |
|
Using load_module()
The load_module() function allows you to load any module by specifying the module name.
For example,
1 |
|