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()[source]¶
Returns
LoadFixtureinstance.
- class testsuite.plugins.common.LoadFixture[source]¶
Load file from static directory.
Example:
def test_something(load): data = load('filename')
- Returns:
LoadFixturecallable instance.
load_binary¶
- testsuite.plugins.common.load_binary()[source]¶
Returns
LoadBinaryFixtureinstance.
load_json¶
- testsuite.plugins.common.load_json()[source]¶
Returns
LoadJsonFixtureinstance.
- 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()[source]¶
Returns
LoadYamlFixtureinstance.
open_file¶
- testsuite.plugins.common.open_file()[source]¶
Returns
OpenFileFixtureinstance.
get_file_path¶
- testsuite.plugins.common.get_file_path()[source]¶
Returns
GetFilePathFixtureinstance.
get_directory_path¶
- testsuite.plugins.common.get_directory_path()[source]¶
Returns
GetDirectoryPathFixtureinstance.
get_search_paths¶
- testsuite.plugins.common.get_search_paths()[source]¶
Returns
GetSearchPathsFixtureinstance.
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() )