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

Commit b2abb50

Browse files
authored
Add ability to use xfail and skip markers (#99)
Allow users to use `xfail` or `skip` markers inside molecule scenario files to modify their execution.
1 parent 3b46557 commit b2abb50

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ This plugin also adds a new pytest option named
5656
when molecule drivers are not loading. Current default is ``None`` but you
5757
can choose marks like ``skip`` or ``xfail``.
5858

59+
Using xfail and skip markers
60+
----------------------------
61+
62+
If you need to skip or ignore a particular scenario, just add either ``xfail``
63+
or ``skip`` to markers list inside its config file.
64+
65+
.. code-block:: yaml
66+
67+
markers:
68+
- xfail # broken scenario, pytest will run it but ignore the result
69+
5970
Installation
6071
------------
6172

src/pytest_molecule/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ def __init__(self, name, parent):
173173
self.molecule_driver = data.get("driver", {}).get("name", "no_driver")
174174
self.add_marker(self.molecule_driver)
175175

176+
# check for known markers and add them
177+
markers = data.get("markers", [])
178+
if "xfail" in markers:
179+
self.add_marker(
180+
pytest.mark.xfail(
181+
reason="Marked as broken by scenario configuration."
182+
)
183+
)
184+
if "skip" in markers:
185+
self.add_marker(
186+
pytest.mark.skip(reason="Disabled by scenario configuration.")
187+
)
188+
176189
# we also add platforms as marks
177190
for platform in data.get("platforms", []):
178191
platform_name = platform["name"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- name: Converge
2+
hosts: all
3+
gather_facts: false
4+
tasks:
5+
6+
- name: Impossible task
7+
fail:
8+
msg: "That playbook should never pass!"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
driver:
3+
name: delegated
4+
5+
platforms:
6+
- name: localhost
7+
8+
provisioner:
9+
name: ansible
10+
log: true
11+
12+
scenario:
13+
test_sequence:
14+
- converge
15+
16+
markers:
17+
- xfail

0 commit comments

Comments
 (0)