From 8dcc8a6afe84487542ec217ed96c8a07cdf16291 Mon Sep 17 00:00:00 2001 From: cdrappier Date: Thu, 20 Aug 2026 03:50:40 +0000 Subject: [PATCH] Clean up the sandbox errors test through a class fixture Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../core/sandbox/test_sandbox_errors.py | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/tests/integration/core/sandbox/test_sandbox_errors.py b/tests/integration/core/sandbox/test_sandbox_errors.py index e5751949..530fead9 100644 --- a/tests/integration/core/sandbox/test_sandbox_errors.py +++ b/tests/integration/core/sandbox/test_sandbox_errors.py @@ -7,7 +7,10 @@ projection drops the field, so it reads as empty too). """ +import asyncio + import pytest +import pytest_asyncio from blaxel.core import SandboxInstance from tests.helpers import default_image, default_labels, default_region, unique_name @@ -17,9 +20,26 @@ class TestSandboxErrors: """Test reading the infrastructure errors recorded on a sandbox.""" - async def test_reads_empty_error_history_on_healthy_sandbox(self): - """A sandbox that never hit an infrastructure failure reports no error.""" + created_sandboxes: list[str] = [] + + @pytest_asyncio.fixture(autouse=True, scope="class", loop_scope="class") + async def cleanup(self, request): + request.cls.created_sandboxes = [] + yield + await asyncio.gather( + *[self._safe_delete_sandbox(n) for n in request.cls.created_sandboxes], + return_exceptions=True, + ) + + async def _safe_delete_sandbox(self, name: str) -> None: + try: + await SandboxInstance.delete(name) + except Exception: + pass + + async def _create_sandbox(self) -> str: name = unique_name("errors") + self.created_sandboxes.append(name) await SandboxInstance.create( { "name": name, @@ -28,20 +48,22 @@ async def test_reads_empty_error_history_on_healthy_sandbox(self): "labels": default_labels, } ) + return name - try: - sandbox = await SandboxInstance.get(name) - - # The shape of an entry (code, fatal, instance, message, time) is - # not exercisable here: covering it would mean provoking a real - # infrastructure failure on the compute plane. - assert isinstance(sandbox.errors, list) - assert sandbox.errors == [] - finally: - await SandboxInstance.delete(name) + async def test_reads_empty_error_history_on_healthy_sandbox(self): + """A sandbox that never hit an infrastructure failure reports no error.""" + sandbox = await SandboxInstance.get(await self._create_sandbox()) + + # The shape of an entry (code, fatal, instance, message, time) is not + # exercisable here: covering it would mean provoking a real + # infrastructure failure on the compute plane. + assert isinstance(sandbox.errors, list) + assert sandbox.errors == [] async def test_listing_does_not_carry_the_error_history(self): """Listings project the field out, so they must not be read for it.""" + await self._create_sandbox() + page = await SandboxInstance.list(limit=1) assert len(page.data) > 0