Add python version checking when using --tox.
This commit is contained in:
parent
58f6604efa
commit
490edbdc48
3 changed files with 19 additions and 1 deletions
|
@ -182,6 +182,10 @@ def parse_args():
|
|||
action='store_true',
|
||||
help='redact sensitive values in output')
|
||||
|
||||
common.add_argument('--check-python',
|
||||
choices=SUPPORTED_PYTHON_VERSIONS,
|
||||
help=argparse.SUPPRESS)
|
||||
|
||||
test = argparse.ArgumentParser(add_help=False, parents=[common])
|
||||
|
||||
test.add_argument('include',
|
||||
|
|
|
@ -12,6 +12,7 @@ from lib.util import (
|
|||
find_python,
|
||||
generate_pip_command,
|
||||
get_docker_completion,
|
||||
ApplicationError,
|
||||
)
|
||||
|
||||
from lib.metadata import (
|
||||
|
@ -67,7 +68,9 @@ class EnvironmentConfig(CommonConfig):
|
|||
if self.python == 'default':
|
||||
self.python = None
|
||||
|
||||
self.python_version = self.python or '.'.join(str(i) for i in sys.version_info[:2])
|
||||
actual_major_minor = '.'.join(str(i) for i in sys.version_info[:2])
|
||||
|
||||
self.python_version = self.python or actual_major_minor
|
||||
self.python_interpreter = args.python_interpreter
|
||||
|
||||
self.delegate = self.tox or self.docker or self.remote
|
||||
|
@ -79,6 +82,9 @@ class EnvironmentConfig(CommonConfig):
|
|||
self.inject_httptester = args.inject_httptester if 'inject_httptester' in args else False # type: bool
|
||||
self.httptester = docker_qualify_image(args.httptester if 'httptester' in args else '') # type: str
|
||||
|
||||
if args.check_python and args.check_python != actual_major_minor:
|
||||
raise ApplicationError('Running under Python %s instead of Python %s as expected.' % (actual_major_minor, args.check_python))
|
||||
|
||||
@property
|
||||
def python_executable(self):
|
||||
"""
|
||||
|
|
|
@ -165,6 +165,14 @@ def delegate_tox(args, exclude, require, integration_targets):
|
|||
if not args.python:
|
||||
cmd += ['--python', version]
|
||||
|
||||
# newer versions of tox do not support older python versions and will silently fall back to a different version
|
||||
# passing this option will allow the delegated ansible-test to verify it is running under the expected python version
|
||||
# tox 3.0.0 dropped official python 2.6 support: https://tox.readthedocs.io/en/latest/changelog.html#v3-0-0-2018-04-02
|
||||
# tox 3.1.3 is the first version to support python 3.8 and later: https://tox.readthedocs.io/en/latest/changelog.html#v3-1-3-2018-08-03
|
||||
# tox 3.1.3 appears to still work with python 2.6, making it a good version to use when supporting all python versions we use
|
||||
# virtualenv 16.0.0 dropped python 2.6 support: https://virtualenv.pypa.io/en/latest/changes/#v16-0-0-2018-05-16
|
||||
cmd += ['--check-python', version]
|
||||
|
||||
if isinstance(args, TestConfig):
|
||||
if args.coverage and not args.coverage_label:
|
||||
cmd += ['--coverage-label', 'tox-%s' % version]
|
||||
|
|
Loading…
Reference in a new issue