An example of using pytest, driven with config options defined in a yaml
Signed-off-by: Adam Israel <adam.israel@canonical.com>
--- /dev/null
+so_host:
+ type: 'string'
+ default: '127.0.0.1'
+ description: 'Host name or ip of the SO'
+so_port:
+ type: int
+ default: 80
+ description: 'Port'
--- /dev/null
+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)])
--- /dev/null
+
+
+def test_host(so_host):
+ assert so_host == '127.0.0.1'
+
+
+def test_port(so_host, so_port):
+ assert so_host == '127.0.0.1'
+ assert so_port == 80