@@ -63,6 +63,11 @@ def pytest_addoption(parser: pytest.Parser) -> None:
63
63
required = True ,
64
64
help = "The CML lab to use" ,
65
65
)
66
+ parser .addoption (
67
+ "--role-include" ,
68
+ action = "store" ,
69
+ help = "The positive search substring to filter the roles" ,
70
+ )
66
71
67
72
68
73
OPTIONS = None
@@ -81,12 +86,28 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
81
86
"""Generate tests.
82
87
83
88
:param metafunc: The pytest metafunc object
89
+ :raises Exception: If the options have not been set
84
90
"""
85
91
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 )
87
95
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 )
90
111
91
112
92
113
def _inventory (
@@ -251,7 +272,15 @@ def ansible_project(
251
272
json .dump (playbook_contents , fh )
252
273
logger .info ("Inventory path: %s" , inventory_path )
253
274
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
+ )
255
284
256
285
257
286
@pytest .fixture
0 commit comments