summaryrefslogtreecommitdiffstats
path: root/src/ansiblelint/testing
diff options
context:
space:
mode:
Diffstat (limited to 'src/ansiblelint/testing')
-rw-r--r--src/ansiblelint/testing/__init__.py3
-rw-r--r--src/ansiblelint/testing/fixtures.py25
2 files changed, 12 insertions, 16 deletions
diff --git a/src/ansiblelint/testing/__init__.py b/src/ansiblelint/testing/__init__.py
index e7f6c1b..9c5463f 100644
--- a/src/ansiblelint/testing/__init__.py
+++ b/src/ansiblelint/testing/__init__.py
@@ -1,4 +1,5 @@
"""Test utils for ansible-lint."""
+
from __future__ import annotations
import os
@@ -13,7 +14,6 @@ from ansiblelint.app import get_app
if TYPE_CHECKING:
# https://github.com/PyCQA/pylint/issues/3240
- # pylint: disable=unsubscriptable-object
CompletedProcess = subprocess.CompletedProcess[Any]
from ansiblelint.errors import MatchError
from ansiblelint.rules import RulesCollection
@@ -156,4 +156,5 @@ def run_ansible_lint(
cwd=cwd,
env=_env,
text=True,
+ encoding="utf-8",
)
diff --git a/src/ansiblelint/testing/fixtures.py b/src/ansiblelint/testing/fixtures.py
index 814a076..05e1ad7 100644
--- a/src/ansiblelint/testing/fixtures.py
+++ b/src/ansiblelint/testing/fixtures.py
@@ -5,21 +5,19 @@ file:
pytest_plugins = ['ansiblelint.testing']
"""
+
from __future__ import annotations
-import copy
from typing import TYPE_CHECKING
import pytest
-from ansiblelint.config import Options, options
+from ansiblelint.config import Options
from ansiblelint.constants import DEFAULT_RULESDIR
from ansiblelint.rules import RulesCollection
from ansiblelint.testing import RunFromText
if TYPE_CHECKING:
- from collections.abc import Iterator
-
from _pytest.fixtures import SubRequest
@@ -29,13 +27,12 @@ if TYPE_CHECKING:
def fixture_default_rules_collection() -> RulesCollection:
"""Return default rule collection."""
assert DEFAULT_RULESDIR.is_dir()
- # For testing we want to manually enable opt-in rules
- test_options = copy.deepcopy(options)
- test_options.enable_list = ["no-same-owner"]
+ config_options = Options()
+ config_options.enable_list = ["no-same-owner"]
# That is instantiated very often and do want to avoid ansible-galaxy
# install errors due to concurrency.
- test_options.offline = True
- return RulesCollection(rulesdirs=[DEFAULT_RULESDIR], options=test_options)
+ config_options.offline = True
+ return RulesCollection(rulesdirs=[DEFAULT_RULESDIR], options=config_options)
@pytest.fixture()
@@ -45,9 +42,10 @@ def default_text_runner(default_rules_collection: RulesCollection) -> RunFromTex
@pytest.fixture()
-def rule_runner(request: SubRequest, config_options: Options) -> RunFromText:
+def rule_runner(request: SubRequest) -> RunFromText:
"""Return runner for a specific rule class."""
rule_class = request.param
+ config_options = Options()
config_options.enable_list.append(rule_class().id)
collection = RulesCollection(options=config_options)
collection.register(rule_class())
@@ -55,9 +53,6 @@ def rule_runner(request: SubRequest, config_options: Options) -> RunFromText:
@pytest.fixture(name="config_options")
-def fixture_config_options() -> Iterator[Options]:
+def fixture_config_options() -> Options:
"""Return configuration options that will be restored after testrun."""
- global options # pylint: disable=global-statement,invalid-name # noqa: PLW0603
- original_options = copy.deepcopy(options)
- yield options
- options = original_options
+ return Options()