# Hello! Presentation and module wrappers for unit testing.

**URL:** <https://forum.ansible.com/t/hello-presentation-and-module-wrappers-for-unit-testing/19587>\
**Category:** Ansible Developer\
**Created:** [October 22, 2015, 11:42am UTC](https://forum.ansible.com/t/hello-presentation-and-module-wrappers-for-unit-testing/19587 "2015-10-22T11:42:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Monforte\_Gonza](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@Jorge\_Monforte\_Gonza](https://forum.ansible.com/u/Jorge_Monforte_Gonza)\
**Post date:** [October 22, 2015, 11:42am UTC](https://forum.ansible.com/t/hello-presentation-and-module-wrappers-for-unit-testing/19587/1 "2015-10-22T11:42:37Z")

</div>

Hello!

My name is Jorge and I’have been using ansible and programming for at least two years now.

I have developed an action\_plugin + module for handling GnuPG keys and encryption and during  
the development I have found hard to test the module as it has over 1000 lines of code so I had to  
build some unit tests to help me test each layer of the module independently.

For doing that and testing the ansible module layer I’ve built a couple of module runners that can  
be called from inside a unittest, one grabs stdout and runs the module parsing the json output,  
the problem with this one is that you can’t use pdb as stdout is redirected.

The other one works patching the AnsibleModule object exit\_json and fail\_json methods so it allows  
you to tinker with pdb but it doesn’t catch if the module is leaking to stdout.

The classes are found in this module.

[https://github.com/llou/gpg\_ansible/blob/master/test/util.py](https://github.com/llou/gpg_ansible/blob/master/test/util.py)

And the functions are called run\_module\_internally and run\_module\_debug. Hope you find them useful.

Keep up with the good job!

Jorge Monforte

---

<div class="post-metadata">

**Author:** ![Francisco\_Martinez1](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@Francisco\_Martinez1](https://forum.ansible.com/u/Francisco_Martinez1)\
**Post date:** [October 22, 2015, 12:04pm UTC](https://forum.ansible.com/t/hello-presentation-and-module-wrappers-for-unit-testing/19587/2 "2015-10-22T12:04:10Z")

</div>

Thanks for sharing!
