Add python.py coverage injector for ansible-test.

This can be used to run Python scripts from the repository with the
correct interpreter and allow collection of code coverage.

Useful for testing contrib inventory scripts.
This commit is contained in:
Matt Clay 2018-09-21 10:33:35 -07:00
parent d3d1ff7990
commit 45b5685037
2 changed files with 17 additions and 0 deletions

View file

@ -105,6 +105,8 @@ def main():
if os.path.basename(__file__) == 'injector.py': if os.path.basename(__file__) == 'injector.py':
args, env = runner() # code coverage collection is baked into the AnsiballZ wrapper when needed args, env = runner() # code coverage collection is baked into the AnsiballZ wrapper when needed
elif os.path.basename(__file__) == 'python.py':
args, env = python() # run arbitrary python commands using the correct python and with optional code coverage
else: else:
args, env = injector() args, env = injector()
@ -119,6 +121,20 @@ def main():
raise raise
def python():
"""
:rtype: list[str], dict[str, str]
"""
if config.coverage_file:
args, env = coverage_command()
else:
args, env = [config.python_interpreter], os.environ.copy()
args += config.arguments[1:]
return args, env
def injector(): def injector():
""" """
:rtype: list[str], dict[str, str] :rtype: list[str], dict[str, str]

View file

@ -0,0 +1 @@
injector.py