Extend pytest so it can accept ansible args
This change adds the ability add ansible arguments to any molecule test. Change-Id: I7159e89d7037b2c669208014d4f814de2eb6f1ad Signed-off-by: Kevin Carter <kecarter@redhat.com>
This commit is contained in:
parent
7ac1086ff5
commit
7d365401c6
@ -0,0 +1,11 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
A new argument has been added to the molecule test setup allowing
|
||||
developers to run tests with Ansible command line arguments. This
|
||||
feature is useful when testing roles that require augmentation,
|
||||
like when tags are needed.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
pytest tests/test_molecule.py --scenario=${NEWROLENAME} --ansible-args='--tags xxx --skip-tags yyy'
|
@ -17,3 +17,4 @@ import os
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption('--scenario', help='scenario setting')
|
||||
parser.addoption('--ansible-args', help='ansible args passed into test runner.')
|
||||
|
@ -18,11 +18,28 @@ import pytest
|
||||
|
||||
|
||||
def test_molecule(pytestconfig):
|
||||
cmd = ['python', '-m', 'molecule', 'test']
|
||||
cmd = ['python', '-m', 'molecule']
|
||||
scenario = pytestconfig.getoption("scenario")
|
||||
if scenario:
|
||||
cmd.extend(['--scenario-name', scenario])
|
||||
else:
|
||||
cmd.append('--all')
|
||||
ansible_args = pytestconfig.getoption("ansible_args")
|
||||
|
||||
assert subprocess.call(cmd) == 0
|
||||
if ansible_args:
|
||||
cmd.append('converge')
|
||||
if scenario:
|
||||
cmd.extend(['--scenario-name', scenario])
|
||||
cmd.append('--')
|
||||
cmd.extend(ansible_args.split())
|
||||
else:
|
||||
cmd.append('test')
|
||||
if scenario:
|
||||
cmd.extend(['--scenario-name', scenario])
|
||||
else:
|
||||
cmd.append('--all')
|
||||
|
||||
try:
|
||||
assert subprocess.call(cmd) == 0
|
||||
finally:
|
||||
if ansible_args:
|
||||
cmd = ['python', '-m', 'molecule', 'destroy']
|
||||
if scenario:
|
||||
cmd.extend(['--scenario-name', scenario])
|
||||
subprocess.call(cmd)
|
||||
|
Loading…
Reference in New Issue
Block a user