Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit 4c2f9f0

Browse files
authored
Make driver and platforms config sections optional (#87)
Current implementation mandates that at least driver and platfroms sections are present in all molecule.yml scenario configuration files. But because those two pieces of information can also come from the base configuration file, it does not feel right to fail when they are not present in the scenario configuration. This commit makes those two sections optional. Missing platfroms section is simply interpreted as an empty list since this does not change the final outcome at all. Missing driver section is treated a bit differently because the driver name is used in a few different places. In order not to break backward-compatibility, we use the "no_driver" string as driver name if the driver section is not present or if the driver name is not set in the scenario config.
1 parent 28f638a commit 4c2f9f0

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ markers_, so you can selectively limit which test types to run:
4242
# Runs scenarios with platform named centos7 and delegated driver:
4343
$ pytest -m delegated -m centos7
4444
45+
If the molecule scenario does not contain information about the driver, the
46+
test associated with it gets a ``no_driver`` mark.
47+
4548
Please note that at this moment molecule will run the entire scenario if the
4649
markers are platforms, this is not *yet* a way to limit which platforms are
4750
executed inside a specific scenario.

pytest_molecule/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def pytest_configure(config):
9595
)
9696
config.option.molecule[driver] = {"available": True}
9797

98+
config.addinivalue_line(
99+
"markers",
100+
"no_driver: mark used for scenarios that do not contain driver info",
101+
)
102+
98103
config.addinivalue_line(
99104
"markers", "molecule: mark used by all molecule scenarios"
100105
)
@@ -151,12 +156,17 @@ def __init__(self, name, parent):
151156
self.funcargs = {}
152157
super().__init__(name, parent)
153158
with open(str(self.fspath), "r") as stream:
154-
data = yaml.load(stream, Loader=yaml.SafeLoader)
159+
# If the molecule.yml file is empty, YAML loader returns None. To
160+
# simplify things down the road, we replace None with an empty
161+
# dict.
162+
data = yaml.load(stream, Loader=yaml.SafeLoader) or {}
163+
155164
# we add the driver as mark
156-
self.molecule_driver = data["driver"]["name"]
165+
self.molecule_driver = data.get("driver", {}).get("name", "no_driver")
157166
self.add_marker(self.molecule_driver)
167+
158168
# we also add platforms as marks
159-
for platform in data["platforms"]:
169+
for platform in data.get("platforms", []):
160170
platform_name = platform["name"]
161171
self.config.addinivalue_line(
162172
"markers",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
platforms:
3+
- name: localhost
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
driver:
3+
name: delegated

0 commit comments

Comments
 (0)