Working with static files¶
Testsuite provides functions to work with static files associated with
testscase. It searches for files in static directoy relative to the current
file.
If your tests is located in tests/test_foo.py
testsuite will search for
the static file filename.txt
in the following order:
Name |
Example path |
---|---|
Per case |
|
Per file |
|
Per package default/ |
|
Static directory |
|
Initial data dirs |
|
Not found |
|
Fixtures¶
load¶
- testsuite.plugins.common.load()¶
Returns
LoadFixture
instance.
- class testsuite.plugins.common.LoadFixture[source]¶
Load file from static directory.
Example:
def test_something(load): data = load('filename')
- Returns:
LoadFixture
callable instance.
load_binary¶
- testsuite.plugins.common.load_binary()¶
Returns
LoadBinaryFixture
instance.
load_json¶
- testsuite.plugins.common.load_json()¶
Returns
LoadJsonFixture
instance.
- class testsuite.plugins.common.LoadJsonFixture[source]¶
Load json doc from static directory.
Json loader runs
json_util.loads(data, ..., *args, **kwargs)
hooks. It does: * bson.json_util.object_hook() * mockserver substitutionExample:
def test_something(load_json): json_obj = load_json('filename.json')
load_yaml¶
- testsuite.plugins.common.load_yaml()¶
Returns
LoadYamlFixture
instance.
open_file¶
- testsuite.plugins.common.open_file()¶
Returns
OpenFileFixture
instance.
get_file_path¶
- testsuite.plugins.common.get_file_path()¶
Returns
GetFilePathFixture
instance.
get_directory_path¶
- testsuite.plugins.common.get_directory_path()¶
Returns
GetDirectoryPathFixture
instance.
get_search_pathes¶
- testsuite.plugins.common.get_search_pathes()¶
Returns
GetSearchPathesFixture
instance.
static_dir¶
initial_data_path¶
testsuite_get_source_path¶
- testsuite.plugins.common.testsuite_get_source_path(path) pathlib.Path [source]¶
Returns source path related to given path.
def test_foo(testsuite_get_source_path): path = testsuite_get_source_path(__file__) ...
testsuite_get_source_directory¶
- testsuite.plugins.common.testsuite_get_source_directory(path) pathlib.Path [source]¶
Session scope fixture. Returns source directory related to given path.
This fixture can be used to access data files in session fixtures, e.g:
|- tests/ |- test_foo.py |- foo.txt
@pytest.fixture(scope='session') def my_data(get_source_directory): return ( testsuite_get_source_directory(__file__) .joinpath('foo.txt') .read_text() )