Add try/except to catch error when site is unavailable

This commit is contained in:
chris committed 2026-03-04 20:41:58 -05:00
1 parent 97635dd3f2
commit 08491297e3
3 files changed
+48 -31

No files matched your search

+11 -6
View File
@@ -1,6 +1,8 @@
"""Tests for the `util` module."""
from datetime import datetime
from httpx import ConnectError
import pytest
import util.convert as uc
import util.drawing as ud
@@ -51,12 +53,15 @@ def test_get_next_draw_date_specified_from_date() -> None:
@pytest.mark.parametrize("game", ['powerball', 'mega-millions'])
def test_scrape_game_history(game) -> None:
"""Test scraping the powerball result page for 1996, 2020, and current year."""
scrape_data = sc.scrape_game_history(game, year=1996)
assert len(scrape_data) in [17, 104]
scrape_data = sc.scrape_game_history(game, year=2020)
assert len(scrape_data) in [104, 105]
scrape_data = sc.scrape_game_history(game)
assert len(scrape_data) in range(0, 105)
try:
scrape_data = sc.scrape_game_history(game, year=1996)
assert len(scrape_data) in [17, 104]
scrape_data = sc.scrape_game_history(game, year=2020)
assert len(scrape_data) in [104, 105]
scrape_data = sc.scrape_game_history(game)
assert len(scrape_data) in range(0, 105)
except ConnectError as ce:
pytest.fail(f"Target scrape site is unavailable: {ce}")
def test_calculate_odds() -> None: