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

Commit bde2c20

Browse files
committed
Enables passing options via MOLECULE_OPTS
If user defines MOLECULE_OPTS environment variable, this will be added to molecule calls made by pytest. Example use: MOLECULE_OPTS=--destroy never
1 parent 438c58b commit bde2c20

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ and runs them as pytest tests.
2828
Once you install pytest-molecule you should be able to just run `pytest` in order
2929
to run molecule on all roles and scenarios.
3030

31+
Optionally you can define `MOLECULE_OPTS` for passing extra parameters to each
32+
molecule call.
33+
3134
Installation
3235
------------
3336

pytest_molecule/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import os
55
import pytest
66
import subprocess
7+
import shlex
78
import sys
9+
from pipes import quote
810

911

1012
def pytest_configure(config):
@@ -58,7 +60,14 @@ def runtest(self):
5860
scenario = folders[-1]
5961
role = folders[-3] # noqa
6062
cmd = [sys.executable, "-m", "molecule", self.name, "-s", scenario]
61-
print("running: %s (from %s)" % (" ".join(cmd), cwd))
63+
64+
# We append the additional options to molecule call, allowing user to
65+
# control how molecule is called by pytest-molecule
66+
opts = os.environ.get("MOLECULE_OPTS")
67+
if opts:
68+
cmd.extend(shlex.split(opts))
69+
70+
print("running: %s (from %s)" % (" ".join(quote(arg) for arg in cmd), cwd))
6271

6372
try:
6473
# Workaround for STDOUT/STDERR line ordering issue:

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ setenv =
3737
# pip: Avoid 2020-01-01 warnings: https://github.com/pypa/pip/issues/6207
3838
PYTHONWARNINGS=ignore:DEPRECATION::pip._internal.cli.base_command
3939
PYTHONDONTWRITEBYTECODE=1
40+
# This should pass these args to molecule, no effect here as this is the default
41+
# but it validates that it accepts extra params.
42+
MOLECULE_OPTS=--destroy always
4043
passenv =
4144
TWINE_*
4245
whitelist_externals =

0 commit comments

Comments
 (0)