pytest example
An example of using pytest, driven with config options defined in a yaml
Signed-off-by: Adam Israel <adam.israel@canonical.com>
diff --git a/test/example/conftest.py b/test/example/conftest.py
new file mode 100644
index 0000000..3798a15
--- /dev/null
+++ b/test/example/conftest.py
@@ -0,0 +1,22 @@
+import yaml
+
+
+config = None
+with open('config.yaml') as f:
+ config = yaml.load(f)
+
+
+def pytest_addoption(parser):
+ for param in config:
+ parser.addoption("--{}".format(param),
+ action="store",
+ type="{}".format(config[param]["type"]),
+ default="{}".format(config[param]["default"]),
+ help="{}".format(config[param]["description"])
+ )
+
+
+def pytest_generate_tests(metafunc):
+ for param in config:
+ if param in metafunc.fixturenames:
+ metafunc.parametrize(param, [metafunc.config.getoption(param)])