buildstream.testing package¶
This package contains various utilities which make it easier to test plugins.
-
check_cache_key_stability(project_path: os.PathLike, cli: buildstream.testing.runcli.Cli) → None¶ Check that the cache key of various elements has not changed.
This ensures that elements do not break cache keys unexpectedly.
The format of the project is expected to be:
./ ./project.conf ./elem1.bst ./elem1.expected ./elem2.bst ./elem2.expected # Or in sub-directories ./mydir/elem3.bst ./mydir/elem3.expected
The
.expectedfile should contain the expected cache key.In order to automatically created the
.expectedfiles, or updated them, you can runpython3 -m buildstream.testing._update_cachekeysin the project’s directory.- Parameters
project_path – Path to a project
cli – a cli object as provided by the fixture
buildstream.testing.runcli.cli()
-
create_repo(kind, directory, subdir='repo')¶ Convenience method for creating a Repo
- Parameters
kind (str) – The kind of repo to create (a source plugin basename). This must have previously been registered using register_repo_kind
directory (str) – The path where the repo will keep a cache
- Returns
A new Repo object
- Return type
(Repo)
-
register_repo_kind(kind, cls, plugin_package)¶ Register a new repo kind.
Registering a repo kind will allow the use of the create_repo method for that kind and include that repo kind in ALL_REPO_KINDS
In addition, repo_kinds registred prior to sourcetests_collection_hook being called will be automatically used to test the basic behaviour of their associated source plugins using the tests in testing._sourcetests.
- Parameters
kind (str) – The kind of repo to create (a source plugin basename)
cls (cls) – A class derived from Repo.
plugin_package (str) – The name of the python package containing the plugin
-
sourcetests_collection_hook(session)¶ Used to hook the templated source plugin tests into a pyest test suite.
This should be called via the pytest_sessionstart hook. The tests in the _sourcetests package will be collected as part of whichever test package this hook is called from.
- Parameters
session (pytest.Session) – The current pytest session