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 00000000000..86e3ea65461 --- /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 00000000000..60575bfe327 --- /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 02fae8dd0f2..8eb3130d48d 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,