ansible/roles/nrpe/molecule/os-family-redhat/tests/conftest.py

24 lines
698 B
Python
Raw Normal View History

2021-08-15 14:24:35 -05:00
"""PyTest Fixtures."""
from __future__ import absolute_import
import os
import pytest
def pytest_runtest_setup():
"""Run tests only when under molecule with testinfra installed."""
try:
# pylint: disable = import-outside-toplevel
import testinfra
except ImportError:
pytest.skip("Test requires testinfra", allow_module_level=True)
if "MOLECULE_INVENTORY_FILE" in os.environ:
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
else:
pytest.skip(
"Test should run only from inside molecule.", allow_module_level=True
)