summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/units/utils/conftest.py18
-rw-r--r--test/units/utils/display/test_broken_cowsay.py2
-rw-r--r--test/units/utils/display/test_display.py2
-rw-r--r--test/units/utils/test_display.py16
4 files changed, 28 insertions, 10 deletions
diff --git a/test/units/utils/conftest.py b/test/units/utils/conftest.py
new file mode 100644
index 0000000000..2528ae3442
--- /dev/null
+++ b/test/units/utils/conftest.py
@@ -0,0 +1,18 @@
+# Copyright: Contributors to the Ansible project
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import annotations
+
+import pytest
+
+from ansible.utils.display import Display
+
+
+@pytest.fixture()
+def display_resource(request):
+ Display._Singleton__instance = None
+
+ def teardown():
+ Display._Singleton__instance = None
+
+ request.addfinalizer(teardown)
diff --git a/test/units/utils/display/test_broken_cowsay.py b/test/units/utils/display/test_broken_cowsay.py
index 50691c229b..2dd697c0a7 100644
--- a/test/units/utils/display/test_broken_cowsay.py
+++ b/test/units/utils/display/test_broken_cowsay.py
@@ -9,7 +9,7 @@ from ansible.utils.display import Display
from unittest.mock import MagicMock
-def test_display_with_fake_cowsay_binary(capsys, mocker):
+def test_display_with_fake_cowsay_binary(capsys, mocker, display_resource):
mocker.patch("ansible.constants.ANSIBLE_COW_PATH", "./cowsay.sh")
mock_popen = MagicMock()
diff --git a/test/units/utils/display/test_display.py b/test/units/utils/display/test_display.py
index af5f6597d0..660db0cf66 100644
--- a/test/units/utils/display/test_display.py
+++ b/test/units/utils/display/test_display.py
@@ -8,7 +8,7 @@ from __future__ import annotations
from ansible.utils.display import Display
-def test_display_basic_message(capsys, mocker):
+def test_display_basic_message(capsys, mocker, display_resource):
# Disable logging
mocker.patch('ansible.utils.display.logger', return_value=None)
diff --git a/test/units/utils/test_display.py b/test/units/utils/test_display.py
index ae7b16bb12..9c2d9c26f6 100644
--- a/test/units/utils/test_display.py
+++ b/test/units/utils/test_display.py
@@ -54,7 +54,7 @@ def test_get_text_width_no_locale(problematic_wcswidth_chars):
pytest.raises(EnvironmentError, get_text_width, problematic_wcswidth_chars[0])
-def test_Display_banner_get_text_width(monkeypatch):
+def test_Display_banner_get_text_width(monkeypatch, display_resource):
locale.setlocale(locale.LC_ALL, '')
display = Display()
display_mock = MagicMock()
@@ -67,7 +67,7 @@ def test_Display_banner_get_text_width(monkeypatch):
assert msg.endswith(stars)
-def test_Display_banner_get_text_width_fallback(monkeypatch):
+def test_Display_banner_get_text_width_fallback(monkeypatch, display_resource):
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
display = Display()
display_mock = MagicMock()
@@ -80,12 +80,12 @@ def test_Display_banner_get_text_width_fallback(monkeypatch):
assert msg.endswith(stars)
-def test_Display_set_queue_parent():
+def test_Display_set_queue_parent(display_resource):
display = Display()
pytest.raises(RuntimeError, display.set_queue, 'foo')
-def test_Display_set_queue_fork():
+def test_Display_set_queue_fork(display_resource):
def test():
display = Display()
display.set_queue('foo')
@@ -96,7 +96,7 @@ def test_Display_set_queue_fork():
assert p.exitcode == 0
-def test_Display_display_fork():
+def test_Display_display_fork(display_resource):
def test():
queue = MagicMock()
display = Display()
@@ -110,7 +110,7 @@ def test_Display_display_fork():
assert p.exitcode == 0
-def test_Display_display_warn_fork():
+def test_Display_display_warn_fork(display_resource):
def test():
queue = MagicMock()
display = Display()
@@ -124,7 +124,7 @@ def test_Display_display_warn_fork():
assert p.exitcode == 0
-def test_Display_display_lock(monkeypatch):
+def test_Display_display_lock(monkeypatch, display_resource):
lock = MagicMock()
display = Display()
monkeypatch.setattr(display, '_lock', lock)
@@ -132,7 +132,7 @@ def test_Display_display_lock(monkeypatch):
lock.__enter__.assert_called_once_with()
-def test_Display_display_lock_fork(monkeypatch):
+def test_Display_display_lock_fork(monkeypatch, display_resource):
lock = MagicMock()
display = Display()
monkeypatch.setattr(display, '_lock', lock)