summaryrefslogtreecommitdiffstats
path: root/deluge/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/conftest.py')
-rw-r--r--deluge/conftest.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/deluge/conftest.py b/deluge/conftest.py
index 55c50a4..d394a27 100644
--- a/deluge/conftest.py
+++ b/deluge/conftest.py
@@ -3,7 +3,7 @@
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#
-
+import asyncio
import tempfile
import warnings
from unittest.mock import Mock, patch
@@ -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:
@@ -137,7 +139,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(
@@ -190,3 +192,18 @@ def mock_mkstemp(tmp_path):
tmp_file = tempfile.mkstemp(dir=tmp_path)
with patch('tempfile.mkstemp', return_value=tmp_file):
yield tmp_file
+
+
+def pytest_collection_modifyitems(session, config, items) -> None:
+ """
+ Automatically runs async tests with pytest_twisted.ensureDeferred
+ """
+ function_items = (item for item in items if isinstance(item, pytest.Function))
+ for function_item in function_items:
+ function = function_item.obj
+ if hasattr(function, '__func__'):
+ # methods need to be unwrapped.
+ function = function.__func__
+ if asyncio.iscoroutinefunction(function):
+ # This is how pytest_twisted marks ensureDeferred tests
+ setattr(function, '_pytest_twisted_mark', 'async_test')