ansible modules unit tests

Lots of code seems to be under test, but not all. I think function-level unit tests would benefit most of the more obscure code, such as authorized_key.parseoptions() ( https://github.com/ansible/ansible/blob/devel/library/system/authorized_key#L174 )
I spent some time writing unit tests for this module, but I couldn’t find an elegant way to make it work with nosetests. The problem is a hardcoded toplevel main() call, that will make a regular import call sys.exit because of the missing boilerplate code.

Some random ideas to enable module unit tests:

  1. Find a way to load an Ansible module without executing main(). For example, with imp.load_module and stripping the main() call before evaluation. Quite ugly.
  2. Refactor all modules to only call main() when name is ‘main’. Lots of work, possibly backwards incompatible.
  3. Before importing, preprocess the module just like hacking/test-module does, to add the missing boilerplate code. Possibly slow.

  4. What do you think?

This is discussed quite a bit, and simply put, unit tests are totally inappropriate for something of this nature.

What we want are integration tests, and are going to be working to roll something out here.

It absolutely shouldn’t be a unit test, because how in the world do you unit test ec2 with any reliability? The code ends up lying to itself.

I’m not interested in considering units for something that needs better testing here, though currently underway is some work to clean up things like Runner’s code to allow unit testing at a cleaner level there.

The modules are going to be tested with playbooks and we hope to have something open-sourced soon in the coming months that provides some end-to-end testing of modules and playbook constructs, in real world scenarios using live systems, that is also user expandable via pull request.