Skip to content

Commit cfdcc05

Browse files
authored
Cleanup tox configs and unit tests (ansible-collections#2219)
SUMMARY As discussed in ansible-collections#2212 cleans up the unit tests to move importing some of the fixtures into conftest.py tox configs needed a little cleanup to ensure that things were consistently in the import path. ISSUE TYPE Feature Pull Request COMPONENT NAME pyproject.toml tests/unit/conftest.py tests/unit/plugins/ tox.ini ADDITIONAL INFORMATION Reviewed-by: Bikouo Aubin
1 parent 159ac00 commit cfdcc05

10 files changed

+164
-81
lines changed

pyproject.toml

+20
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,23 @@ builtins = "_"
5151

5252
[tool.mypy]
5353
disable_error_code = ["import-untyped"]
54+
55+
[tool.ruff]
56+
line-length = 120
57+
58+
[tool.ruff.lint]
59+
# "F401" - unused-imports - We use these imports to maintain historic Interfaces
60+
# "E402" - import not at top of file - General Ansible style puts the documentation at the top.
61+
unfixable = ["F401"]
62+
ignore = ["F401", "E402"]
63+
64+
[tool.pytest]
65+
xfail_strict = true
66+
67+
[tool.coverage.report]
68+
exclude_lines = [
69+
# Have to re-enable the standard pragma
70+
"pragma: no cover",
71+
# Don't complain if tests don't hit defensive assertion code:
72+
"raise NotImplementedError",
73+
]

tests/unit/conftest.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This file is part of Ansible
4+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
# While it may seem appropriate to import our custom fixtures here, the pytest_ansible pytest plugin
7+
# isn't as agressive as the ansible_test._util.target.pytest.plugins.ansible_pytest_collections plugin
8+
# when it comes to rewriting the import paths and as such we can't import fixtures via their
9+
# absolute import path or across collections.

tests/unit/plugins/conftest.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This file is part of Ansible
4+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
# pylint: disable=unused-import
7+
8+
import pytest
9+
10+
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
11+
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify

tests/unit/plugins/modules/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
# Copyright (c) 2017 Ansible Project
24
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
35

tests/unit/plugins/modules/dms_endpoint/test_compare_params.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
# Copyright: (c) 2023, Ansible Project
44
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
55

6-
import pytest
76
from unittest.mock import patch
87

8+
import pytest
9+
910
from ansible_collections.community.aws.plugins.modules.dms_endpoint import compare_params
1011

12+
1113
@pytest.mark.parametrize(
1214
"described_params,created_params,expected_result",
1315
[

tests/unit/plugins/modules/test_data_pipeline.py

-10
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@
2525

2626
from ansible_collections.amazon.aws.plugins.module_utils.botocore import HAS_BOTO3
2727

28-
# Magic... Incorrectly identified by pylint as unused
29-
# isort: off
30-
# pylint: disable=unused-import
31-
32-
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
33-
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify
34-
35-
# pylint: enable=unused-import
36-
# isort: on
37-
3828
from ansible_collections.community.aws.plugins.modules import data_pipeline
3929

4030
if not HAS_BOTO3:

tests/unit/plugins/modules/test_directconnect_connection.py

-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414

1515
from ansible_collections.amazon.aws.plugins.module_utils.botocore import HAS_BOTO3
1616

17-
# Magic... Incorrectly identified by pylint as unused
18-
# isort: off
19-
# pylint: disable=unused-import
20-
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
21-
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify
22-
23-
# pylint: enable=unused-import
24-
# isort: on
25-
2617
from ansible_collections.community.aws.plugins.modules import directconnect_connection
2718

2819
if not HAS_BOTO3:

tests/unit/plugins/modules/test_directconnect_link_aggregation_group.py

-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
2020
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info
2121

22-
# Magic... Incorrectly identified by pylint as unused
23-
# isort: off
24-
# pylint: disable=unused-import
25-
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
26-
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify
27-
28-
# pylint: enable=unused-import
29-
# isort: on
30-
3122
from ansible_collections.community.aws.plugins.modules import directconnect_link_aggregation_group as lag_module
3223

3324
if not HAS_BOTO3:

tests/unit/plugins/modules/test_directconnect_virtual_interface.py

-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414

1515
from ansible_collections.amazon.aws.plugins.module_utils.botocore import HAS_BOTO3
1616

17-
# Magic... Incorrectly identified by pylint as unused
18-
# isort: off
19-
# pylint: disable=unused-import
20-
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
21-
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify
22-
23-
# pylint: enable=unused-import
24-
# isort: on
25-
2617
from ansible_collections.community.aws.plugins.modules import directconnect_virtual_interface
2718

2819
if not HAS_BOTO3:

0 commit comments

Comments
 (0)