diff --git a/tests/unit/module_utils/conftest.py b/tests/unit/module_utils/conftest.py index 8bc13c4d55c..f90055615d1 100644 --- a/tests/unit/module_utils/conftest.py +++ b/tests/unit/module_utils/conftest.py @@ -7,10 +7,12 @@ import json import sys from io import BytesIO +import warnings import pytest import ansible.module_utils.basic +import ansible.module_utils.common from ansible.module_utils.six import PY3, string_types from ansible.module_utils._text import to_bytes from ansible.module_utils.common._collections_compat import MutableMapping @@ -23,6 +25,13 @@ def stdin(mocker, request): old_argv = sys.argv sys.argv = ['ansible_unittest'] + for var in ["_global_warnings", "_global_deprecations"]: + if hasattr(ansible.module_utils.common.warnings, var): + setattr(ansible.module_utils.common.warnings, var, []) + else: + # No need to reset the value + warnings.warn("deprecated") + if isinstance(request.param, string_types): args = request.param elif isinstance(request.param, MutableMapping): diff --git a/tests/unit/module_utils/core/ansible_aws_module/test_minimal_versions.py b/tests/unit/module_utils/core/ansible_aws_module/test_minimal_versions.py index 92373392271..8a1b07b39a9 100644 --- a/tests/unit/module_utils/core/ansible_aws_module/test_minimal_versions.py +++ b/tests/unit/module_utils/core/ansible_aws_module/test_minimal_versions.py @@ -10,6 +10,7 @@ import botocore import boto3 import json +import warnings from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from pprint import pprint diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000000..04a0e5bf7d1 --- /dev/null +++ b/tox.ini @@ -0,0 +1,20 @@ +[tox] +skipsdist=True +envlist = clean,ansible{2.12,2.13}-py{38,39,310}-{with_constraints,without_constraints} + +[testenv] +deps = + pytest + pytest-cov + ansible2.12: ansible-core>2.12,<2.13 + ansible2.13: ansible-core>2.13,<2.14 + !ansible2.12-!ansible2.13: ansible-core + pytest-ansible-units + -rtest-requirements.txt + with_constraints: -rtests/unit/constraints.txt +commands = pytest --cov-report html --cov plugins {posargs:tests/} + +[testenv:clean] +deps = coverage +skip_install = true +commands = coverage erase