summaryrefslogtreecommitdiffstats
path: root/src/ansiblelint/testing/fixtures.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ansiblelint/testing/fixtures.py25
1 files changed, 10 insertions, 15 deletions
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()