tests/plugins/bst2.py: Testing error handling of loading wrong plugin versions.
diff --git a/setup.cfg b/setup.cfg
index 7c2c139..7dfa257 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -12,7 +12,7 @@
 
 [tool:pytest]
 addopts = --verbose --basetemp ./tmp --pep8 --pylint --pylint-rcfile=.pylintrc --durations=20
-norecursedirs = tests/integration/project integration-cache tmp __pycache__ .eggs
+norecursedirs = tests/integration/project tests/plugins/bst2 integration-cache tmp __pycache__ .eggs
 python_files = tests/*/*.py
 pep8maxlinelength = 119
 pep8ignore =
diff --git a/tests/plugins/bst2.py b/tests/plugins/bst2.py
new file mode 100644
index 0000000..ca7529d
--- /dev/null
+++ b/tests/plugins/bst2.py
@@ -0,0 +1,60 @@
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+#
+# This test case tests the failure modes of loading a plugin
+# after it has already been discovered via it's origin.
+#
+
+import os
+import pytest
+
+from buildstream._exceptions import ErrorDomain
+from tests.testutils import cli  # pylint: disable=unused-import
+from buildstream import _yaml
+
+
+DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "bst2")
+
+
+# Sets up the element.bst file so that it requires a source
+# or element plugin.
+#
+def setup_element(project_path, plugin_type, plugin_name):
+    element_path = os.path.join(project_path, "element.bst")
+
+    if plugin_type == "elements":
+        element = {"kind": plugin_name}
+    else:
+        element = {"kind": "manual", "sources": [{"kind": plugin_name}]}
+
+    _yaml.dump(element, element_path)
+
+
+####################################################
+#                     Tests                        #
+####################################################
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("plugin_type", ["elements", "sources"])
+@pytest.mark.parametrize("plugin", ["bst2", "malformed"])
+def test_plugin_bst2(cli, datafiles, plugin_type, plugin):
+    project = str(datafiles)
+    project_conf_path = os.path.join(project, "project.conf")
+    project_conf = {
+        "name": "test",
+        "plugins": [
+            {
+                "origin": "local",
+                "path": plugin_type,
+                plugin_type: {
+                    plugin: 0
+                }
+            }
+        ]
+    }
+    _yaml.dump(project_conf, project_conf_path)
+
+    setup_element(project, plugin_type, plugin)
+
+    result = cli.run(project=project, args=["show", "element.bst"])
+    result.assert_main_error(ErrorDomain.PLUGIN, "plugin-version-mismatch")
diff --git a/tests/plugins/bst2/elements/bst2.py b/tests/plugins/bst2/elements/bst2.py
new file mode 100644
index 0000000..34a7e43
--- /dev/null
+++ b/tests/plugins/bst2/elements/bst2.py
@@ -0,0 +1,19 @@
+from buildstream import Element
+
+
+class Found(Element):
+    BST_MIN_VERSION = "2.0"
+
+    def configure(self, node):
+        pass
+
+    def preflight(self):
+        pass
+
+    def get_unique_key(self):
+        return {}
+
+
+# Plugin entry point
+def setup():
+    return Found
diff --git a/tests/plugins/bst2/elements/malformed.py b/tests/plugins/bst2/elements/malformed.py
new file mode 100644
index 0000000..d3fe97a
--- /dev/null
+++ b/tests/plugins/bst2/elements/malformed.py
@@ -0,0 +1,19 @@
+from buildstream import Element
+
+
+class Found(Element):
+    BST_MIN_VERSION = 5
+
+    def configure(self, node):
+        pass
+
+    def preflight(self):
+        pass
+
+    def get_unique_key(self):
+        return {}
+
+
+# Plugin entry point
+def setup():
+    return Found
diff --git a/tests/plugins/bst2/sources/bst2.py b/tests/plugins/bst2/sources/bst2.py
new file mode 100644
index 0000000..4ab40f0
--- /dev/null
+++ b/tests/plugins/bst2/sources/bst2.py
@@ -0,0 +1,32 @@
+from buildstream import Source
+
+
+class Found(Source):
+    BST_MIN_VERSION = "2.0"
+
+    def configure(self, node):
+        pass
+
+    def preflight(self):
+        pass
+
+    def get_unique_key(self):
+        return {}
+
+    def load_ref(self, node):
+        pass
+
+    def get_ref(self):
+        return {}
+
+    def set_ref(self, ref, node):
+        pass
+
+    def is_cached(self):
+        return False
+
+
+# Plugin entry point
+def setup():
+
+    return Found
diff --git a/tests/plugins/bst2/sources/malformed.py b/tests/plugins/bst2/sources/malformed.py
new file mode 100644
index 0000000..786e3d6
--- /dev/null
+++ b/tests/plugins/bst2/sources/malformed.py
@@ -0,0 +1,32 @@
+from buildstream import Source
+
+
+class Found(Source):
+    BST_MIN_VERSION = "a pony"
+
+    def configure(self, node):
+        pass
+
+    def preflight(self):
+        pass
+
+    def get_unique_key(self):
+        return {}
+
+    def load_ref(self, node):
+        pass
+
+    def get_ref(self):
+        return {}
+
+    def set_ref(self, ref, node):
+        pass
+
+    def is_cached(self):
+        return False
+
+
+# Plugin entry point
+def setup():
+
+    return Found