[Tests] Fix component warning in Plugin tests

The component fixture was warning about existing registered components since
the standalone client was setup before the componentregistry test was performed.
The problem is due to fixture ordering with the setup fixture running
first since it was marked with autouse followed by component fixture.

* Fixed warning by moving component fixture as a dependency of the set_up fixture
* Cleaned up unneeded code
* Added try..except to catch CorePluginBase KeyError deregistering
RPCServer since component fixture already removed it.
* Ignore test-specific Twisted readBody warnings
This commit is contained in:
Calum Lind 2023-02-28 12:25:17 +00:00
parent f67fb4d520
commit 9ce8afe507
No known key found for this signature in database
GPG key ID: 90597A687B836BA3
5 changed files with 13 additions and 15 deletions

View file

@ -137,7 +137,7 @@ def common_fixture(config_dir, request, monkeypatch, listen_port):
@pytest_twisted.async_yield_fixture(scope='function')
async def component(request):
async def component():
"""Verify component registry is clean, and clean up after test."""
if len(_component._ComponentRegistry.components) != 0:
warnings.warn(

View file

@ -7,7 +7,6 @@ import pytest
import pytest_twisted
from twisted.internet import defer
import deluge.component as component
from deluge.common import fsize, fspeed
from deluge.ui.client import client
@ -21,17 +20,15 @@ def print_totals(totals):
print('down:', fsize(totals['total_download'] - totals['total_payload_download']))
@pytest.mark.usefixtures('component')
class TestStatsPlugin:
@pytest_twisted.async_yield_fixture(autouse=True)
async def set_up(self):
async def set_up(self, component):
defer.setDebugging(True)
client.start_standalone()
client.core.enable_plugin('Stats')
await component.start()
yield
client.stop_standalone()
await component.shutdown()
@defer.inlineCallbacks
def test_client_totals(self):

View file

@ -8,7 +8,6 @@
import pytest
import pytest_twisted
import deluge.component as component
from deluge.core.core import Core
from deluge.core.rpcserver import RPCServer
from deluge.tests import common
@ -16,10 +15,9 @@ from deluge.tests import common
common.disable_new_release_check()
@pytest.mark.usefixtures('component')
class TestWebUIPlugin:
@pytest_twisted.async_yield_fixture(autouse=True)
async def set_up(self, request):
async def set_up(self, request, component):
self = request.instance
self.rpcserver = RPCServer(listen=False)
self.core = Core()
@ -27,11 +25,9 @@ class TestWebUIPlugin:
yield
def on_shutdown(result):
del self.rpcserver
del self.core
await component.shutdown().addCallback(on_shutdown)
await component.shutdown()
del self.rpcserver
del self.core
def test_enable_webui(self):
if 'WebUi' not in self.core.get_available_plugins():

View file

@ -34,7 +34,10 @@ class CorePluginBase(PluginBase):
log.debug('CorePlugin initialized..')
def __del__(self):
component.get('RPCServer').deregister_object(self)
try:
component.get('RPCServer').deregister_object(self)
except KeyError:
log.debug('RPCServer already deregistered')
def enable(self):
super().enable()

View file

@ -23,6 +23,8 @@ markers = [
]
filterwarnings = [
"ignore::DeprecationWarning:gi",
"ignore::DeprecationWarning:twisted.internet.gireactor:43",
"ignore::DeprecationWarning:twisted.internet.gireactor",
"ignore:twisted.web.resource.*:DeprecationWarning",
"ignore:Using readBody.*:DeprecationWarning",
"ignore:resume_data is deprecated.*:DeprecationWarning:deluge.core.alertmanager",
]