Skip to content

Commit

Permalink
fix: try-except -> pytest.raises
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Jul 30, 2024
1 parent dbc56a5 commit 1e6bee0
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,8 @@ async def test_apply_kwargs(self, *, x: int, y: int):
async def test_apply_timeout(self):
executor = TimeoutExecutor(1)
result = await executor.delay(anyio.sleep, 1.5)
try:
with pytest.raises(TimeoutError):
await result.delay(0.1)
except Exception as exc: # noqa: BLE001
assert isinstance(exc, TimeoutError) # noqa: PT017
else:
raise Exception("TimeoutError does not occur") # noqa: TRY002

@pytest.mark.parametrize("x", range(TEST_SIZE))
async def test_apply_lambda(self, x: int):
Expand All @@ -135,12 +131,8 @@ async def lambdalike() -> int:
raise RuntimeError("error")

result = await executor.delay(lambdalike)
try:
with pytest.raises(TimeoutError):
await result.delay(0.1)
except Exception as exc: # noqa: BLE001
assert isinstance(exc, TimeoutError) # noqa: PT017
else:
raise Exception("TimeoutError does not occur") # noqa: TRY002

async def test_terminator(self):
executor = TimeoutExecutor(0.5)
Expand All @@ -150,12 +142,8 @@ async def temp_func() -> None:

result = await executor.delay(temp_func)
assert isinstance(result, AsyncResult)
try:
with pytest.raises(TimeoutError):
await result.delay()
except Exception as exc: # noqa: BLE001
assert isinstance(exc, TimeoutError) # noqa: PT017
else:
raise Exception("TimeoutError does not occur") # noqa: TRY002

assert result._terminator.is_active is True # noqa: SLF001

Expand Down

0 comments on commit 1e6bee0

Please sign in to comment.