diff --git a/sdks/python/boxlite/simplebox.py b/sdks/python/boxlite/simplebox.py index e6082c4e9..d9f61a18c 100644 --- a/sdks/python/boxlite/simplebox.py +++ b/sdks/python/boxlite/simplebox.py @@ -292,6 +292,15 @@ async def collect_stderr(): error_message=error_message, ) + async def metrics(self): + """Get box metrics (CPU, memory usage).""" + if not self._started: + raise RuntimeError( + "Box not started. Use 'async with SimpleBox(...) as box:' " + "or call 'await box.start()' first." + ) + return await self._box.metrics() + async def stop(self): """ Stop the box and release resources. diff --git a/sdks/python/tests/test_simplebox.py b/sdks/python/tests/test_simplebox.py new file mode 100644 index 000000000..3f6d9601c --- /dev/null +++ b/sdks/python/tests/test_simplebox.py @@ -0,0 +1,18 @@ +"""Integration tests for the async SimpleBox convenience wrapper.""" + +from __future__ import annotations + +import pytest + +import boxlite + +pytestmark = [pytest.mark.integration, pytest.mark.asyncio] + + +async def test_simplebox_metrics(shared_runtime): + """Async SimpleBox exposes box metrics like SyncSimpleBox.""" + async with boxlite.SimpleBox(image="alpine:latest", runtime=shared_runtime) as box: + await box.exec("echo", "test") + metrics = await box.metrics() + assert metrics is not None + assert metrics.commands_executed_total >= 1