Skip to content

Commit

Permalink
import tox.ini (#1090)
Browse files Browse the repository at this point in the history
import tox.ini

much faster than the other tests (less than 5 minutes), we don't need to build the collection first or to pull the ansible-test container
works from anyway, no need to copy the collection in .ansible/collections/ansible_collections/amazon/aws first
generate HTML coverage, e.g: https://c8cca5e7f93c66c3bfca-5f43057c94d0562db863016349fecb6f.ssl.cf5.rackcdn.com/1090/f1142b4b561938403637af89bfe76169da025d75/check/cloud-tox-py39/562db5d/docs/coverage/index.html
test with py39 currently, but we can extend the matrix
adjustment to properly reset some global variables. The problem doesn't happen with ansible-test because the tests are run in parallel and thus, there is no shared memory space.

Reviewed-by: Mark Chappell <None>
  • Loading branch information
goneri authored Sep 30, 2022
1 parent b553d94 commit 1cac4da
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/unit/module_utils/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pprint import pprint
import pytest
import json
import warnings

try:
import botocore
Expand Down
20 changes: 20 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1cac4da

Please sign in to comment.