Skip to content

Commit 645cb9d

Browse files
authored
Merge pull request #2 from cidrblock/main
Add role filter, add logging locations
2 parents 1a9bd21 + 5f2c2da commit 645cb9d

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

.config/dictionary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ addopts
33
cliargs
44
dataclass
55
dumpxml
6+
filterwarnings
67
fixturenames
78
fqcn
89
getppid
@@ -18,6 +19,7 @@ popen
1819
pylibssh
1920
pylibsshext
2021
rootdir
22+
skipif
2123
testpaths
2224
virl
2325
virsh

src/pytest_ansible_network_integration/__init__.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def pytest_addoption(parser: pytest.Parser) -> None:
6363
required=True,
6464
help="The CML lab to use",
6565
)
66+
parser.addoption(
67+
"--role-include",
68+
action="store",
69+
help="The positive search substring to filter the roles",
70+
)
6671

6772

6873
OPTIONS = None
@@ -81,12 +86,28 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
8186
"""Generate tests.
8287
8388
:param metafunc: The pytest metafunc object
89+
:raises Exception: If the options have not been set
8490
"""
8591
if "integration_test_path" in metafunc.fixturenames:
86-
rootdir = metafunc.config.getoption("integration_tests_path")
92+
if not OPTIONS:
93+
raise Exception("pytest_configure not called")
94+
rootdir = Path(OPTIONS.integration_tests_path)
8795
roles = [path for path in Path(rootdir).iterdir() if path.is_dir()]
88-
role_names = [role.name for role in roles]
89-
metafunc.parametrize("integration_test_path", roles, ids=role_names)
96+
test_ids = [role.name for role in roles]
97+
98+
tests = []
99+
for role in roles:
100+
if OPTIONS.role_include and OPTIONS.role_include not in role.name:
101+
tests.append(
102+
pytest.param(
103+
role,
104+
marks=pytest.mark.skipif(True, reason="Role not included by filter"),
105+
)
106+
)
107+
else:
108+
tests.append(pytest.param(role))
109+
110+
metafunc.parametrize("integration_test_path", tests, ids=test_ids)
90111

91112

92113
def _inventory(
@@ -251,7 +272,15 @@ def ansible_project(
251272
json.dump(playbook_contents, fh)
252273
logger.info("Inventory path: %s", inventory_path)
253274
logger.info("Playbook path: %s", playbook_path)
254-
return AnsibleProject(playbook=playbook_path, inventory=inventory_path, directory=tmp_path)
275+
276+
return AnsibleProject(
277+
playbook=playbook_path,
278+
inventory=inventory_path,
279+
directory=tmp_path,
280+
role=integration_test_path.name,
281+
log_file=Path(f"~/test_logs/{integration_test_path.name}.log").resolve(),
282+
playbook_artifact=Path(f"~/test_logs/{integration_test_path.name}.json").resolve(),
283+
)
255284

256285

257286
@pytest.fixture

src/pytest_ansible_network_integration/defs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
class AnsibleProject:
3030
"""Ansible project."""
3131

32-
playbook: Path
33-
inventory: Path
3432
directory: Path
33+
inventory: Path
34+
log_file: Path
35+
playbook_artifact: Path
36+
playbook: Path
37+
role: str
3538

3639

3740
class SshWrapper:

0 commit comments

Comments
 (0)