ansible/test/units/utils
Matt Clay 9e67953b2e
Fix collection loader and add unit tests. (#58701)
* Use `compile` before `eval` in collection loader.

This fixes two issues:

1. File names are available when tracing execution, such as with code coverage.
2. Future statements are not inherited from the collection loader.

* Add unit tests for collection loading.

These tests verify several things:

1. That unit tests can import code from collections when the collection loader is installed.
2. That tracing reports the correct file and line numbers (to support code coverage).
3. That collection code does not inherit __future__ statements from the collection loader.

* Update unit test handling of the collection loader.

Since the collection loader is installed simply by importing ansible.plugins.loader,
we may already have a collection loader installed when the test runs. This occurs if
any other tests are collected which use that import during collection. Until that code
is moved into an initialization function to avoid loading during import, the unit tests
will need to replace any existing collection loaders so that they reflect the desired
configuration.

* Insert into sys.modules before calling exec.

This is a requirement of PEP 302.

It will prevent recursion errors when importing the current module or using a relative import.

* Use the correct value for __package__ in modules.

This allows using relative imports in collections.

* Add warning about modifying code for trace test.

* Add test for relative import in collection.

* Add __init__.py to collection to satisfy pylint.

The relative-beyond-top-level rule in pylint may not be appropriate for collections.
However, until that rule is disabled for collections this will keep tests passing.
2019-07-09 17:31:33 -07:00
..
fixtures/collections/ansible_collections/my_namespace/my_collection/plugins Fix collection loader and add unit tests. (#58701) 2019-07-09 17:31:33 -07:00
__init__.py
amazon_placebo_fixtures.py
kubevirt_fixtures.py kubevirt: even more unit tests (#58593) 2019-07-05 20:35:32 +10:00
test_cleanup_tmp_file.py Use atexit to cleanup tmp dirs (#56532) 2019-06-28 16:19:27 -04:00
test_collection_loader.py Fix collection loader and add unit tests. (#58701) 2019-07-09 17:31:33 -07:00
test_context_objects.py Move the arguments module into cli/ and context_objects into utils 2019-01-03 18:12:23 -08:00
test_encrypt.py Skip tests with unsatisfied deps (#55853) 2019-06-28 13:09:36 -07:00
test_helpers.py
test_shlex.py
test_unsafe_proxy.py Add unit tests for unsafe_proxy (#47887) 2018-11-01 16:42:32 -05:00
test_vars.py Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00