From 0ea18ecb0b7dcbb0b10698f9f2f56667fff5b827 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 1 Jun 2022 16:02:53 -0700 Subject: [PATCH] ansible-test - Prefer unittest.mock for core. --- changelogs/fragments/ansible-test-ansible-core-mock.yml | 3 +++ test/lib/ansible_test/_data/pytest/config/ansible-core.ini | 4 ++++ .../_data/{pytest.ini => pytest/config/default.ini} | 0 test/lib/ansible_test/_internal/commands/units/__init__.py | 7 ++++++- 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible-test-ansible-core-mock.yml create mode 100644 test/lib/ansible_test/_data/pytest/config/ansible-core.ini rename test/lib/ansible_test/_data/{pytest.ini => pytest/config/default.ini} (100%) diff --git a/changelogs/fragments/ansible-test-ansible-core-mock.yml b/changelogs/fragments/ansible-test-ansible-core-mock.yml new file mode 100644 index 00000000000000..86e3ea65461b81 --- /dev/null +++ b/changelogs/fragments/ansible-test-ansible-core-mock.yml @@ -0,0 +1,3 @@ +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. diff --git a/test/lib/ansible_test/_data/pytest/config/ansible-core.ini b/test/lib/ansible_test/_data/pytest/config/ansible-core.ini new file mode 100644 index 00000000000000..60575bfe32731d --- /dev/null +++ b/test/lib/ansible_test/_data/pytest/config/ansible-core.ini @@ -0,0 +1,4 @@ +[pytest] +xfail_strict = true +# avoid using 'mock_use_standalone_module = true' so package maintainers can avoid packaging 'mock' +junit_family = xunit1 diff --git a/test/lib/ansible_test/_data/pytest.ini b/test/lib/ansible_test/_data/pytest/config/default.ini similarity index 100% rename from test/lib/ansible_test/_data/pytest.ini rename to test/lib/ansible_test/_data/pytest/config/default.ini diff --git a/test/lib/ansible_test/_internal/commands/units/__init__.py b/test/lib/ansible_test/_internal/commands/units/__init__.py index bd5b3e2b816e94..ef65df29d45cf8 100644 --- a/test/lib/ansible_test/_internal/commands/units/__init__.py +++ b/test/lib/ansible_test/_internal/commands/units/__init__.py @@ -234,6 +234,11 @@ 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: cmd = [ 'pytest', @@ -243,7 +248,7 @@ def command_units(args): # type: (UnitsConfig) -> None '--color', 'yes' if args.color else 'no', '-p', 'no:cacheprovider', - '-c', os.path.join(ANSIBLE_TEST_DATA_ROOT, 'pytest.ini'), + '-c', os.path.join(ANSIBLE_TEST_DATA_ROOT, 'pytest', 'config', config_name), '--junit-xml', os.path.join(ResultType.JUNIT.path, 'python%s-%s-units.xml' % (python.version, test_context)), '--strict-markers', # added in pytest 4.5.0 '--rootdir', data_context().content.root,