diff --git a/.backport-fix-plugins-unit-tests-unload-plugins-upon-their-deletion.patch.swp b/.backport-fix-plugins-unit-tests-unload-plugins-upon-their-deletion.patch.swp new file mode 100644 index 0000000000000000000000000000000000000000..c37589ac827acd9520764ea67e8dc0dd59fc47bc Binary files /dev/null and b/.backport-fix-plugins-unit-tests-unload-plugins-upon-their-deletion.patch.swp differ diff --git a/backport-fix-plugins-unit-tests-unload-plugins-upon-their-deletion.patch b/backport-fix-plugins-unit-tests-unload-plugins-upon-their-deletion.patch new file mode 100644 index 0000000000000000000000000000000000000000..c8f2b6da294fbe485b9aac07c036fb9922c4d3a3 --- /dev/null +++ b/backport-fix-plugins-unit-tests-unload-plugins-upon-their-deletion.patch @@ -0,0 +1,93 @@ +From 9ee057a4ccf3170deeb4626aa2387085d2ec6d5b Mon Sep 17 00:00:00 2001 +From: Jan Kolarik +Date: Tue, 13 Sep 2022 14:35:10 +0200 +Subject: [PATCH] Fix plugins unit tests + unload plugins upon their deletion + +Conflict:NA +Reference:https://github.com/rpm-software-management/dnf/commit/7ef317db99efeddb66905134292b0fe05e2ed58c +--- + dnf/plugin.py | 8 ++++++-- + tests/api/test_dnf_base.py | 24 +++++++++++++++++++----- + 2 files changed, 25 insertions(+), 7 deletions(-) + +diff --git a/dnf/plugin.py b/dnf/plugin.py +index b083727deb..d2f46ce340 100644 +--- a/dnf/plugin.py ++++ b/dnf/plugin.py +@@ -98,6 +98,9 @@ def __init__(self): + self.plugin_cls = [] + self.plugins = [] + ++ def __del__(self): ++ self._unload() ++ + def _caller(self, method): + for plugin in self.plugins: + try: +@@ -164,8 +167,9 @@ def run_transaction(self): + self._caller('transaction') + + def _unload(self): +- logger.debug(_('Plugins were unloaded')) +- del sys.modules[DYNAMIC_PACKAGE] ++ if DYNAMIC_PACKAGE in sys.modules: ++ logger.log(dnf.logging.DDEBUG, 'Plugins were unloaded.') ++ del sys.modules[DYNAMIC_PACKAGE] + + def unload_removed_plugins(self, transaction): + """ +diff --git a/tests/api/test_dnf_base.py b/tests/api/test_dnf_base.py +index e84e272b77..19754b072e 100644 +--- a/tests/api/test_dnf_base.py ++++ b/tests/api/test_dnf_base.py +@@ -7,10 +7,23 @@ + import dnf + import dnf.conf + ++import tests.support ++ + from .common import TestCase + from .common import TOUR_4_4 + + ++def conf_with_empty_plugins(): ++ """ ++ Use empty configuration to avoid importing plugins from default paths ++ which would lead to crash of other tests. ++ """ ++ conf = tests.support.FakeConf() ++ conf.plugins = True ++ conf.pluginpath = [] ++ return conf ++ ++ + class DnfBaseApiTest(TestCase): + def setUp(self): + self.base = dnf.Base(dnf.conf.Conf()) +@@ -75,13 +88,12 @@ def test_transaction(self): + self.assertHasType(self.base.transaction, dnf.db.group.RPMTransaction) + + def test_init_plugins(self): +- # Base.init_plugins(disabled_glob=(), enable_plugins=(), cli=None) ++ # Base.init_plugins() + self.assertHasAttr(self.base, "init_plugins") + +- # disable plugins to avoid calling dnf.plugin.Plugins._load() multiple times +- # which causes the tests to crash +- self.base.conf.plugins = False +- self.base.init_plugins(disabled_glob=(), enable_plugins=(), cli=None) ++ self.base._conf = conf_with_empty_plugins() ++ ++ self.base.init_plugins() + + def test_pre_configure_plugins(self): + # Base.pre_configure_plugins() +@@ -99,6 +111,8 @@ def test_unload_plugins(self): + # Base.unload_plugins() + self.assertHasAttr(self.base, "unload_plugins") + ++ self.base._conf = conf_with_empty_plugins() ++ + self.base.init_plugins() + self.base.unload_plugins() + \ No newline at end of file diff --git a/dnf.spec b/dnf.spec index 77576c79048999b3dc30ee68506c0bf25669ba9e..23569ea34f7abc0c9f5ddd4c970b7955bff62df0 100644 --- a/dnf.spec +++ b/dnf.spec @@ -3,7 +3,7 @@ Name: dnf Version: 4.14.0 -Release: 6 +Release: 7 Summary: A software package manager that manages packages on Linux distributions. License: GPLv2+ and GPLv2 and GPL URL: https://github.com/rpm-software-management/dnf @@ -23,6 +23,8 @@ Patch6000: dnf-4.10.0-sw.patch Patch6001: 0001-Add-loongarch-architecture-support.patch %endif +Patch6003: backport-fix-plugins-unit-tests-unload-plugins-upon-their-deletion.patch + BuildArch: noarch BuildRequires: cmake gettext systemd bash-completion python3-sphinx Requires: python3-%{name} = %{version}-%{release} libreport-filesystem @@ -104,8 +106,6 @@ mkdir build-py3 sed -i '154,160d' tests/api/test_dnf_base.py sed -i '51,55d' tests/api/test_dnf_logging.py -rm -rf tests/test_plugin.py - %build pushd build-py3 %cmake .. -DPYTHON_DESIRED:FILEPATH=%{__python3} @@ -248,6 +248,9 @@ popd %{_mandir}/man8/%{name}-automatic.8* %changelog +* Tue Dec 20 2022 chenhaixing - 4.14.0-7 +- DESC:fix test cases failed in tests/test_plugin.py + * Thu Dec 15 2022 chenhaixing - 4.14.0-6 - DESC:remove tests