New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Idea: Provide import hooks for module/library code #14133
Comments
just produce the file using hacking/test-module |
Ah, I wasn't aware of this, thanks. However, that doesn't appear to do in-depth unit testing, like importing specific classes/functions and running them in a test case. Maybe I'm missing something? |
no, but it produces the importable version of the script Brian Coca |
Thanks, I see that now on further reading. Looking at the setup.py file and my installed version of Ansible, it appears this isn't included with the installed distribution, as only the How would you suggest testing modules that live outside of ansible's core with this? For context, I'm trying to test modules in https://github.com/openstack/openstack-ansible/tree/master/playbooks/plugins. |
those you should be able to test with a normal import, its only the library/task/modules that use ansible.module_utils. require extra magic as they are not importable. |
Thanks, I'll play around with that. The main thrust of the import hooks was to provide a way to get to the actual importable modules, since like you say, they do work. I think in that specific case we wanted to have our tests in the root |
As this appears to be more of a general use question rather than a bug/issue, I'm going to go ahead and close this now. If you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved. Thank you! |
Currently, when trying to write Python unit tests for Ansible module/library code, one must resort to doing their own import hacks, like described in https://nicolai86.eu/blog/posts/2014-02-05/testing-ansible-libraries/.
To avoid this, I wrote a new library,
ansible_importer
, that uses Python import hooks to find Ansible modules without peppering the file system with__init__.py
files or having to rewrite the import code every time.It may be useful for ansible itself to provide this functionality. I would propose that it be something like
ansible.imports.activate('abs/path/to/yaml/code')
.The text was updated successfully, but these errors were encountered: