Skip to content

Commit

Permalink
Cleanup tox configs and unit tests (#2219) (#2228)
Browse files Browse the repository at this point in the history
This is a manual backport of PR #2219 as merged into main (cfdcc05).
SUMMARY
As discussed in #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

Reviewed-by: GomathiselviS <gomathiselvi@gmail.com>
  • Loading branch information
tremble authored Feb 3, 2025
1 parent 9f75252 commit 4a98551
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 79 deletions.
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,33 @@ known_ansible_community_aws = ["ansible_collections.community.aws"]

[tool.flynt]
transform-joins = true

[tool.flake8]
# E123, E125 skipped as they are invalid PEP-8.
show-source = true
ignore = ["E123", "E125", "E203", "E402", "E501", "E741", "F401", "F811", "F841", "W503"]
max-line-length = 160
builtins = "_"

[tool.mypy]
disable_error_code = ["import-untyped"]

[tool.ruff]
line-length = 120

[tool.ruff.lint]
# "F401" - unused-imports - We use these imports to maintain historic Interfaces
# "E402" - import not at top of file - General Ansible style puts the documentation at the top.
unfixable = ["F401"]
ignore = ["F401", "E402"]

[tool.pytest]
xfail_strict = true

[tool.coverage.report]
exclude_lines = [
# Have to re-enable the standard pragma
"pragma: no cover",
# Don't complain if tests don't hit defensive assertion code:
"raise NotImplementedError",
]
9 changes: 9 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

# While it may seem appropriate to import our custom fixtures here, the pytest_ansible pytest plugin
# isn't as agressive as the ansible_test._util.target.pytest.plugins.ansible_pytest_collections plugin
# when it comes to rewriting the import paths and as such we can't import fixtures via their
# absolute import path or across collections.
11 changes: 11 additions & 0 deletions tests/unit/plugins/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-

# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

# pylint: disable=unused-import

import pytest

from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify
2 changes: 2 additions & 0 deletions tests/unit/plugins/modules/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Copyright: (c) 2023, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

import pytest
from unittest.mock import patch

import pytest

from ansible_collections.community.aws.plugins.modules.dms_endpoint import compare_params


@pytest.mark.parametrize(
"described_params,created_params,expected_result",
[
Expand Down
10 changes: 0 additions & 10 deletions tests/unit/plugins/modules/test_data_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@

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

# Magic... Incorrectly identified by pylint as unused
# isort: off
# pylint: disable=unused-import

from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify

# pylint: enable=unused-import
# isort: on

from ansible_collections.community.aws.plugins.modules import data_pipeline

if not HAS_BOTO3:
Expand Down
9 changes: 0 additions & 9 deletions tests/unit/plugins/modules/test_directconnect_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@

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

# Magic... Incorrectly identified by pylint as unused
# isort: off
# pylint: disable=unused-import
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify

# pylint: enable=unused-import
# isort: on

from ansible_collections.community.aws.plugins.modules import directconnect_connection

if not HAS_BOTO3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info

# Magic... Incorrectly identified by pylint as unused
# isort: off
# pylint: disable=unused-import
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify

# pylint: enable=unused-import
# isort: on

from ansible_collections.community.aws.plugins.modules import directconnect_link_aggregation_group as lag_module

if not HAS_BOTO3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@

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

# Magic... Incorrectly identified by pylint as unused
# isort: off
# pylint: disable=unused-import
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify

# pylint: enable=unused-import
# isort: on

from ansible_collections.community.aws.plugins.modules import directconnect_virtual_interface

if not HAS_BOTO3:
Expand Down
Loading

0 comments on commit 4a98551

Please sign in to comment.