|
|
59c9d3 |
From 3ef5ec915ea4b5e6fe7d25542f0daccef278c01e Mon Sep 17 00:00:00 2001
|
|
|
59c9d3 |
From: Jan Kolarik <jkolarik@redhat.com>
|
|
|
59c9d3 |
Date: Tue, 13 Sep 2022 14:35:10 +0200
|
|
|
59c9d3 |
Subject: [PATCH] Fix plugins unit tests + unload plugins upon their deletion
|
|
|
59c9d3 |
|
|
|
59c9d3 |
---
|
|
|
59c9d3 |
dnf/plugin.py | 8 ++++++--
|
|
|
59c9d3 |
tests/api/test_dnf_base.py | 24 +++++++++++++++++++-----
|
|
|
59c9d3 |
2 files changed, 25 insertions(+), 7 deletions(-)
|
|
|
59c9d3 |
|
|
|
59c9d3 |
diff --git a/dnf/plugin.py b/dnf/plugin.py
|
|
|
59c9d3 |
index b083727d..d2f46ce3 100644
|
|
|
59c9d3 |
--- a/dnf/plugin.py
|
|
|
59c9d3 |
+++ b/dnf/plugin.py
|
|
|
59c9d3 |
@@ -98,6 +98,9 @@ class Plugins(object):
|
|
|
59c9d3 |
self.plugin_cls = []
|
|
|
59c9d3 |
self.plugins = []
|
|
|
59c9d3 |
|
|
|
59c9d3 |
+ def __del__(self):
|
|
|
59c9d3 |
+ self._unload()
|
|
|
59c9d3 |
+
|
|
|
59c9d3 |
def _caller(self, method):
|
|
|
59c9d3 |
for plugin in self.plugins:
|
|
|
59c9d3 |
try:
|
|
|
59c9d3 |
@@ -164,8 +167,9 @@ class Plugins(object):
|
|
|
59c9d3 |
self._caller('transaction')
|
|
|
59c9d3 |
|
|
|
59c9d3 |
def _unload(self):
|
|
|
59c9d3 |
- logger.debug(_('Plugins were unloaded'))
|
|
|
59c9d3 |
- del sys.modules[DYNAMIC_PACKAGE]
|
|
|
59c9d3 |
+ if DYNAMIC_PACKAGE in sys.modules:
|
|
|
59c9d3 |
+ logger.log(dnf.logging.DDEBUG, 'Plugins were unloaded.')
|
|
|
59c9d3 |
+ del sys.modules[DYNAMIC_PACKAGE]
|
|
|
59c9d3 |
|
|
|
59c9d3 |
def unload_removed_plugins(self, transaction):
|
|
|
59c9d3 |
"""
|
|
|
59c9d3 |
diff --git a/tests/api/test_dnf_base.py b/tests/api/test_dnf_base.py
|
|
|
59c9d3 |
index e84e272b..19754b07 100644
|
|
|
59c9d3 |
--- a/tests/api/test_dnf_base.py
|
|
|
59c9d3 |
+++ b/tests/api/test_dnf_base.py
|
|
|
59c9d3 |
@@ -7,10 +7,23 @@ from __future__ import unicode_literals
|
|
|
59c9d3 |
import dnf
|
|
|
59c9d3 |
import dnf.conf
|
|
|
59c9d3 |
|
|
|
59c9d3 |
+import tests.support
|
|
|
59c9d3 |
+
|
|
|
59c9d3 |
from .common import TestCase
|
|
|
59c9d3 |
from .common import TOUR_4_4
|
|
|
59c9d3 |
|
|
|
59c9d3 |
|
|
|
59c9d3 |
+def conf_with_empty_plugins():
|
|
|
59c9d3 |
+ """
|
|
|
59c9d3 |
+ Use empty configuration to avoid importing plugins from default paths
|
|
|
59c9d3 |
+ which would lead to crash of other tests.
|
|
|
59c9d3 |
+ """
|
|
|
59c9d3 |
+ conf = tests.support.FakeConf()
|
|
|
59c9d3 |
+ conf.plugins = True
|
|
|
59c9d3 |
+ conf.pluginpath = []
|
|
|
59c9d3 |
+ return conf
|
|
|
59c9d3 |
+
|
|
|
59c9d3 |
+
|
|
|
59c9d3 |
class DnfBaseApiTest(TestCase):
|
|
|
59c9d3 |
def setUp(self):
|
|
|
59c9d3 |
self.base = dnf.Base(dnf.conf.Conf())
|
|
|
59c9d3 |
@@ -75,13 +88,12 @@ class DnfBaseApiTest(TestCase):
|
|
|
59c9d3 |
self.assertHasType(self.base.transaction, dnf.db.group.RPMTransaction)
|
|
|
59c9d3 |
|
|
|
59c9d3 |
def test_init_plugins(self):
|
|
|
59c9d3 |
- # Base.init_plugins(disabled_glob=(), enable_plugins=(), cli=None)
|
|
|
59c9d3 |
+ # Base.init_plugins()
|
|
|
59c9d3 |
self.assertHasAttr(self.base, "init_plugins")
|
|
|
59c9d3 |
|
|
|
59c9d3 |
- # disable plugins to avoid calling dnf.plugin.Plugins._load() multiple times
|
|
|
59c9d3 |
- # which causes the tests to crash
|
|
|
59c9d3 |
- self.base.conf.plugins = False
|
|
|
59c9d3 |
- self.base.init_plugins(disabled_glob=(), enable_plugins=(), cli=None)
|
|
|
59c9d3 |
+ self.base._conf = conf_with_empty_plugins()
|
|
|
59c9d3 |
+
|
|
|
59c9d3 |
+ self.base.init_plugins()
|
|
|
59c9d3 |
|
|
|
59c9d3 |
def test_pre_configure_plugins(self):
|
|
|
59c9d3 |
# Base.pre_configure_plugins()
|
|
|
59c9d3 |
@@ -99,6 +111,8 @@ class DnfBaseApiTest(TestCase):
|
|
|
59c9d3 |
# Base.unload_plugins()
|
|
|
59c9d3 |
self.assertHasAttr(self.base, "unload_plugins")
|
|
|
59c9d3 |
|
|
|
59c9d3 |
+ self.base._conf = conf_with_empty_plugins()
|
|
|
59c9d3 |
+
|
|
|
59c9d3 |
self.base.init_plugins()
|
|
|
59c9d3 |
self.base.unload_plugins()
|
|
|
59c9d3 |
|
|
|
59c9d3 |
--
|
|
|
59c9d3 |
2.38.1
|
|
|
59c9d3 |
|