diff --git a/changelogs/fragments/ansible-test-plugin-classification.yml b/changelogs/fragments/ansible-test-plugin-classification.yml new file mode 100644 index 00000000000..b1996cda6bf --- /dev/null +++ b/changelogs/fragments/ansible-test-plugin-classification.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test - integration and unit test change detection now works for filter, lookup and test plugins diff --git a/test/lib/ansible_test/_internal/classification.py b/test/lib/ansible_test/_internal/classification.py index 3c5dd6a5948..cc6fe643a2c 100644 --- a/test/lib/ansible_test/_internal/classification.py +++ b/test/lib/ansible_test/_internal/classification.py @@ -608,6 +608,12 @@ class PathMapper: FOCUSED_TARGET: target is not None, } + if is_subdir(path, data_context().content.plugin_paths['filter']): + return self._simple_plugin_tests('filter', name) + + if is_subdir(path, data_context().content.plugin_paths['lookup']): + return self._simple_plugin_tests('lookup', name) + if (is_subdir(path, data_context().content.plugin_paths['terminal']) or is_subdir(path, data_context().content.plugin_paths['cliconf']) or is_subdir(path, data_context().content.plugin_paths['netconf'])): @@ -632,6 +638,9 @@ class PathMapper: 'units': 'all', } + if is_subdir(path, data_context().content.plugin_paths['test']): + return self._simple_plugin_tests('test', name) + return None def _classify_collection(self, path): # type: (str) -> t.Optional[t.Dict[str, str]] @@ -874,6 +883,31 @@ class PathMapper: return None # unknown, will result in fall-back to run all tests + def _simple_plugin_tests(self, plugin_type, plugin_name): # type: (str, str) -> t.Dict[str, t.Optional[str]] + """ + Return tests for the given plugin type and plugin name. + This function is useful for plugin types which do not require special processing. + """ + if plugin_name == '__init__': + return all_tests(self.args, True) + + integration_target = self.integration_targets_by_name.get('%s_%s' % (plugin_type, plugin_name)) + + if integration_target: + integration_name = integration_target.name + else: + integration_name = None + + units_path = os.path.join(data_context().content.unit_path, 'plugins', plugin_type, 'test_%s.py' % plugin_name) + + if units_path not in self.units_paths: + units_path = None + + return dict( + integration=integration_name, + units=units_path, + ) + def all_tests(args, force=False): """