summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-03 14:15:12 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-04 20:16:38 +0900
commit53b7374d6962b750e453a85d793f1a59038b4a65 (patch)
treedaf9c9d6112500c8389462cbc878c88467cea399
parent60bae6d028878b5c9b0b1b723faffd0ca16dabef (diff)
downloadbuildstream-53b7374d6962b750e453a85d793f1a59038b4a65.tar.gz
tests/plugins/loading.py: Added test for loading pip pluings
This test is automatically skipped when the required package is not installed, which can happen when running pytest directly, which is supported in order to help distribution maintainers test whether BuildStream works properly on their distribution.
-rw-r--r--tests/plugins/loading.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/plugins/loading.py b/tests/plugins/loading.py
index 152f4080b..1c5dc4546 100644
--- a/tests/plugins/loading.py
+++ b/tests/plugins/loading.py
@@ -42,6 +42,37 @@ def setup_element(project_path, plugin_type, plugin_name):
_yaml.roundtrip_dump(element, element_path)
+# This function is used for pytest skipif() expressions.
+#
+# Tests which require our plugins in tests/plugins/pip-samples need
+# to check if these plugins are installed, they are only guaranteed
+# to be installed when running tox, but not when using pytest directly
+# to test that BuildStream works when integrated in your system.
+#
+def pip_sample_packages():
+ import pkg_resources
+
+ required = {"sample-plugins"}
+ installed = {pkg.key for pkg in pkg_resources.working_set} # pylint: disable=not-an-iterable
+ missing = required - installed
+
+ if missing:
+ return False
+
+ return True
+
+
+SAMPLE_PACKAGES_SKIP_REASON = """
+The sample plugins package used to test pip plugin origins is not installed.
+
+This is usually tested automatically with `tox`, if you are running
+`pytest` directly then you can install these plugins directly using pip.
+
+The plugins are located in the tests/plugins/sample-plugins directory
+of your BuildStream checkout.
+"""
+
+
####################################################
# Tests #
####################################################
@@ -303,3 +334,18 @@ def test_deprecation_warning_suppressed_specifically(cli, datafiles, plugin_type
result = cli.run(project=project, args=["show", "element.bst"])
result.assert_success()
assert "Here is some detail." not in result.stderr
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("plugin_type", [("elements"), ("sources")])
+@pytest.mark.skipif("not pip_sample_packages()", reason=SAMPLE_PACKAGES_SKIP_REASON)
+def test_pip_origin_load_success(cli, datafiles, plugin_type):
+ project = str(datafiles)
+
+ update_project(
+ project, {"plugins": [{"origin": "pip", "package-name": "sample-plugins", plugin_type: ["sample"],}]},
+ )
+ setup_element(project, plugin_type, "sample")
+
+ result = cli.run(project=project, args=["show", "element.bst"])
+ result.assert_success()