Skip to content

Commit fb33c15

Browse files
committed
Isolate exception testing in a new test
Improve the testing of exceptions using pytest.raises(). Closes #77
1 parent 8fdcc73 commit fb33c15

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/tests/test_flip_coins_function.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@pytest.mark.parametrize(
1111
"coin_flip_count",
12-
list(range(11)) + list(range(10, 200, 10)) + [1, 2] * 30
12+
list(range(1, 12)) + list(range(10, 200, 10)) + [1, 2] * 30
1313
)
1414
def test_multiple_coin_flips(coin_flip_count: int) -> None:
1515
"""Example test case
@@ -20,13 +20,18 @@ def test_multiple_coin_flips(coin_flip_count: int) -> None:
2020
Returns:
2121
None
2222
"""
23-
try:
24-
coin_flip_result = src.flip_coins.flip_coins(
25-
coin_flip_count=coin_flip_count,
26-
chosen_side="heads"
23+
coin_flip_result = src.flip_coins.flip_coins(
24+
coin_flip_count=coin_flip_count,
25+
chosen_side="heads"
26+
)
27+
logging.debug("coin_flip_result = %s", coin_flip_result)
28+
assert coin_flip_result["outcome"][0] in ["won", "lost", "tie"]
29+
30+
31+
def test_multiple_coin_flip_zero_times() -> None:
32+
"""Test the exception handling of flip_coins when asked to flip 0 coins"""
33+
with pytest.raises(AssertionError):
34+
src.flip_coins.flip_coins(
35+
coin_flip_count=0,
36+
chosen_side="tails"
2737
)
28-
logging.debug("coin_flip_result = %s", coin_flip_result)
29-
assert coin_flip_result["outcome"][0] in ["won", "lost", "tie"]
30-
except AssertionError as error:
31-
# Validate that trying to flip 0 coins causes an error
32-
assert isinstance(error, AssertionError) and coin_flip_count == 0

0 commit comments

Comments
 (0)