diff --git a/changelogs/fragments/ansible-test-venv-system-site-packages.yml b/changelogs/fragments/ansible-test-venv-system-site-packages.yml new file mode 100644 index 00000000000..1e4526e7736 --- /dev/null +++ b/changelogs/fragments/ansible-test-venv-system-site-packages.yml @@ -0,0 +1,2 @@ +minor_changes: +- "ansible-test - added a ``--venv-system-site-packages`` option for use with the ``--venv`` option" diff --git a/test/lib/ansible_test/_internal/cli.py b/test/lib/ansible_test/_internal/cli.py index abc55d795ea..95aa700d8ca 100644 --- a/test/lib/ansible_test/_internal/cli.py +++ b/test/lib/ansible_test/_internal/cli.py @@ -653,6 +653,12 @@ def add_environments(parser, isolated_delegation=True): action='store_true', help='run from ansible-test managed virtual environments') + venv = parser.add_argument_group(title='venv arguments') + + venv.add_argument('--venv-system-site-packages', + action='store_true', + help='enable system site packages') + if not isolated_delegation: environments.set_defaults( docker=None, diff --git a/test/lib/ansible_test/_internal/config.py b/test/lib/ansible_test/_internal/config.py index c6a034ac1d1..3cad3f3747a 100644 --- a/test/lib/ansible_test/_internal/config.py +++ b/test/lib/ansible_test/_internal/config.py @@ -45,6 +45,7 @@ class EnvironmentConfig(CommonConfig): self.local = args.local is True self.venv = args.venv + self.venv_system_site_packages = args.venv_system_site_packages self.python = args.python if 'python' in args else None # type: str diff --git a/test/lib/ansible_test/_internal/delegation.py b/test/lib/ansible_test/_internal/delegation.py index 46db7ca6dbb..24630277e8a 100644 --- a/test/lib/ansible_test/_internal/delegation.py +++ b/test/lib/ansible_test/_internal/delegation.py @@ -167,14 +167,20 @@ def delegate_venv(args, # type: EnvironmentConfig if needs_httptester: display.warning('Use --docker or --remote to enable httptester for tests marked "needs/httptester": %s' % ', '.join(needs_httptester)) - venvs = dict((version, os.path.join(ResultType.TMP.path, 'delegation', 'python%s' % version)) for version in versions) - venvs = dict((version, path) for version, path in venvs.items() if create_virtual_environment(args, version, path)) + if args.venv_system_site_packages: + suffix = '-ssp' + else: + suffix = '' + + venvs = dict((version, os.path.join(ResultType.TMP.path, 'delegation', 'python%s%s' % (version, suffix))) for version in versions) + venvs = dict((version, path) for version, path in venvs.items() if create_virtual_environment(args, version, path, args.venv_system_site_packages)) if not venvs: raise ApplicationError('No usable virtual environment support found.') options = { '--venv': 0, + '--venv-system-site-packages': 0, } with tempdir() as inject_path: