[stable-2.13] ansible-test - Adjust unit test mock usage. (#77961) (#77999)

(cherry picked from commit 23914d3f0b)

Co-authored-by: Matt Clay <matt@mystile.com>
pull/78006/head
Matt Clay 3 years ago committed by GitHub
parent ae380e3bef
commit 567a295c00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,2 @@
minor_changes:
- ansible-test - Avoid using the ``mock_use_standalone_module`` setting for ``pytest`` when running ansible-core unit tests.
This has no effect on unit tests for collections.
- ansible-test - Avoid using the ``mock_use_standalone_module`` setting for unit tests running on Python 3.8 or later.

@ -1,4 +0,0 @@
[pytest]
xfail_strict = true
# avoid using 'mock_use_standalone_module = true' so package maintainers can avoid packaging 'mock'
junit_family = xunit1

@ -1,4 +1,4 @@
[pytest]
xfail_strict = true
mock_use_standalone_module = true
# avoid using 'mock_use_standalone_module = true' so package maintainers can avoid packaging 'mock'
junit_family = xunit1

@ -0,0 +1,4 @@
[pytest]
xfail_strict = true
mock_use_standalone_module = true
junit_family = xunit1

@ -21,6 +21,7 @@ from ...util import (
ANSIBLE_TEST_DATA_ROOT,
display,
is_subdir,
str_to_version,
SubprocessError,
ANSIBLE_LIB_ROOT,
ANSIBLE_TEST_TARGET_ROOT,
@ -234,12 +235,21 @@ def command_units(args): # type: (UnitsConfig) -> None
if args.requirements_mode == 'only':
sys.exit()
if data_context().content.is_ansible:
config_name = 'ansible-core.ini'
else:
config_name = 'default.ini'
for test_context, python, paths, env in test_sets:
# When using pytest-mock, make sure that features introduced in Python 3.8 are available to older Python versions.
# This is done by enabling the mock_use_standalone_module feature, which forces use of mock even when unittest.mock is available.
# Later Python versions have not introduced additional unittest.mock features, so use of mock is not needed as of Python 3.8.
# If future Python versions introduce new unittest.mock features, they will not be available to older Python versions.
# Having the cutoff at Python 3.8 also eases packaging of ansible-core since no supported controller version requires the use of mock.
#
# NOTE: This only affects use of pytest-mock.
# Collection unit tests may directly import mock, which will be provided by ansible-test when it installs requirements using pip.
# Although mock is available for ansible-core unit tests, they should import units.compat.mock instead.
if str_to_version(python.version) < (3, 8):
config_name = 'legacy.ini'
else:
config_name = 'default.ini'
cmd = [
'pytest',
'--forked',

Loading…
Cancel
Save