From d779f25fa1c70454946a183d2bdd8ace4a4d612d Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Fri, 21 Sep 2018 10:33:35 -0700 Subject: [PATCH] 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. (cherry picked from commit 45b5685037f27a642161e48bb81b08bccdee277e) --- test/runner/injector/injector.py | 16 ++++++++++++++++ test/runner/injector/python.py | 1 + 2 files changed, 17 insertions(+) create mode 120000 test/runner/injector/python.py diff --git a/test/runner/injector/injector.py b/test/runner/injector/injector.py index 31bc0cbc375..ac7fec51176 100755 --- a/test/runner/injector/injector.py +++ b/test/runner/injector/injector.py @@ -110,6 +110,8 @@ def main(): args, env, require_cwd = cover() else: args, env = runner() + elif os.path.basename(__file__) == 'python.py': + args, env = python() # run arbitrary python commands using the correct python and with optional code coverage else: args, env = injector() @@ -142,6 +144,20 @@ def main(): 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(): """ :rtype: list[str], dict[str, str] diff --git a/test/runner/injector/python.py b/test/runner/injector/python.py new file mode 120000 index 00000000000..1f9d09cbf2a --- /dev/null +++ b/test/runner/injector/python.py @@ -0,0 +1 @@ +injector.py \ No newline at end of file