Skip to content

Commit d7ba46b

Browse files
committed
use custom exception instead of hacky ZeroDivisionError
1 parent 586d596 commit d7ba46b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

tests/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Success(Exception):
2+
"""Raise in case of success"""
3+
4+
pass

tests/test_session_handler.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from fundus.scraping.session import CONFIG, SessionHandler
6+
from tests.exceptions import Success
67

78

89
class TestContext:
@@ -41,14 +42,10 @@ def test_thread_safety(self):
4142
session_handler = SessionHandler()
4243

4344
def set_context(timeout: int = 100):
44-
with pytest.raises(ZeroDivisionError):
45+
with pytest.raises(Success):
4546
with session_handler.context(TIMEOUT=timeout):
4647
assert session_handler.get_session().timeout == timeout
47-
48-
# We intentionally trigger a ZeroDivisionError to ensure the context
49-
# is executed in the thread. Using a precise exception type
50-
# (ZeroDivisionError) prevents masking other potential errors.
51-
return 1 / 0
48+
raise Success
5249

5350
def set_context_fail():
5451
with pytest.raises(AssertionError):

0 commit comments

Comments
 (0)