summaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
authordev <dev@local>2026-10-05 16:40:10 +0530
committerdev <dev@local>2026-10-05 16:40:10 +0530
commited4889134aa77d912d7e0fc0d69f7def0dd772fc (patch)
tree4317f0b80491c02e37d1f752bce8462b5b4b24ff /tests/conftest.py
Working agent before enhancements: 205 tests passing
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..5a19bfb
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,77 @@
+"""Shared test fixtures.
+
+Agentux's core is async, but the suite runs on a bare pytest install. This
+module supplies the small hook that executes ``async def`` tests, so the
+project needs no pytest plugin (``pytest-asyncio``) and no asyncio-mode
+configuration to be maintained alongside the code.
+"""
+
+from __future__ import annotations
+
+import asyncio
+import inspect
+
+import pytest
+
+from agentux.config import Config
+from agentux.providers.mock import MockProvider
+from agentux.tools.filesystem import FilesystemTool
+from agentux.tools.project import ProjectTool
+from agentux.tools.registry import ToolRegistry
+from agentux.tools.shell import ShellTool
+
+
+def pytest_pyfunc_call(pyfuncitem):
+ """Run coroutine tests on a fresh event loop."""
+ test_function = pyfuncitem.obj
+ if not inspect.iscoroutinefunction(test_function):
+ return None
+
+ kwargs = {
+ name: pyfuncitem.funcargs[name]
+ for name in pyfuncitem._fixtureinfo.argnames
+ }
+ loop = asyncio.new_event_loop()
+ try:
+ asyncio.set_event_loop(loop)
+ loop.run_until_complete(test_function(**kwargs))
+ finally:
+ asyncio.set_event_loop(None)
+ loop.close()
+ return True
+
+
+def run_async(coroutine):
+ """Run a coroutine from a synchronous test."""
+ loop = asyncio.new_event_loop()
+ try:
+ return loop.run_until_complete(coroutine)
+ finally:
+ loop.close()
+
+
+@pytest.fixture
+def config(tmp_path):
+ return Config(
+ api_key="test-key",
+ base_url="http://api.test/v1",
+ model="test-model",
+ working_dir=str(tmp_path),
+ max_steps=10,
+ )
+
+
+@pytest.fixture
+def provider():
+ return MockProvider([])
+
+
+@pytest.fixture
+def registry(tmp_path):
+ return ToolRegistry(
+ [
+ FilesystemTool(root=str(tmp_path)),
+ ShellTool(cwd=str(tmp_path)),
+ ProjectTool(root=str(tmp_path)),
+ ]
+ )