[Tests] Use tmp_path for test logfile

Daemon logfile were being stored in dir where tests were started from
which cluttered up local dev env.

Entry point logfiles are stored in config dir since getting tmp_path in
set_up was a bit too tricky.
This commit is contained in:
Calum Lind 2022-03-02 08:51:29 +00:00
parent 7b1a0ef89c
commit e90f6c7eef
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
4 changed files with 10 additions and 18 deletions

View File

@ -59,8 +59,9 @@ def mock_callback():
@pytest.fixture
def config_dir(tmp_path):
deluge.configmanager.set_config_dir(tmp_path)
yield tmp_path
config_dir = tmp_path / 'config'
deluge.configmanager.set_config_dir(config_dir)
yield config_dir
@pytest_twisted.async_yield_fixture()
@ -84,9 +85,10 @@ async def client(request, config_dir, monkeypatch, listen_port):
@pytest_twisted.async_yield_fixture
async def daemon(request, config_dir):
async def daemon(request, config_dir, tmp_path):
listen_port = DEFAULT_LISTEN_PORT
logfile = f'daemon_{request.node.name}.log'
logfile = tmp_path / 'daemon.log'
if hasattr(request.cls, 'daemon_custom_script'):
custom_script = request.cls.daemon_custom_script
else:

View File

@ -113,7 +113,7 @@ class ProcessOutputHandler(protocol.ProcessProtocol):
self.shutdown_func = shutdown_func
self.log_output = ''
self.stderr_out = ''
self.logfile = logfile.replace('/', '_') if logfile else None
self.logfile = logfile
self.print_stdout = print_stdout
self.print_stderr = print_stderr
self.quit_d = None

View File

@ -4,8 +4,6 @@
# See LICENSE for more details.
#
import os.path
import pytest
from twisted.internet import defer
from twisted.internet.error import CannotListenError
@ -43,15 +41,7 @@ class DaemonBase:
port_range=10,
extra_callbacks=None,
):
if logfile == '':
logfile = 'daemon_%s.log' % self.id()
# We are running py.test
if hasattr(pytest, 'config'):
if self.basetemp:
if not os.path.exists(self.basetemp):
os.makedirs(self.basetemp)
logfile = os.path.join(self.basetemp, logfile)
logfile = f'daemon_{self.id()}.log' if logfile == '' else logfile
for dummy in range(port_range):
try:

View File

@ -58,7 +58,7 @@ class StringFileDescriptor:
class UIBaseTestCase:
def set_up(self):
common.setup_test_logger(level='info', prefix=self.id())
common.setup_test_logger(level='info', prefix=self.config_dir / self.id())
return component.start()
def tear_down(self):
@ -75,7 +75,7 @@ class UIWithDaemonBaseTestCase(UIBaseTestCase, DaemonBase):
def set_up(self):
d = self.common_set_up()
common.setup_test_logger(level='info', prefix=self.id())
common.setup_test_logger(level='info', prefix=self.config_dir / self.id())
return d