fix: add @pytest.mark.asyncio to async test methods
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m23s

Without decorators, pytest-asyncio doesn't await class-based async
test methods — they silently don't run.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-03-18 15:55:16 -05:00
parent 5a4c96cbdb
commit 93e0ab9a63

View File

@ -14,16 +14,24 @@ import pytest
from unittest.mock import AsyncMock, patch
import discord
# ---------------------------------------------------------------------------
# Helpers / shared fixtures
# ---------------------------------------------------------------------------
def make_card(player_id=42, p_name="Mike Trout", rarity_color="FFD700",
image="https://example.com/card.png", headshot=None,
franchise="Los Angeles Angels", bbref_id="troutmi01",
fangr_id=None, strat_code="420420",
mlbclub="Los Angeles Angels", cardset_name="2024 Season"):
def make_card(
player_id=42,
p_name="Mike Trout",
rarity_color="FFD700",
image="https://example.com/card.png",
headshot=None,
franchise="Los Angeles Angels",
bbref_id="troutmi01",
fangr_id=None,
strat_code="420420",
mlbclub="Los Angeles Angels",
cardset_name="2024 Season",
):
"""
Build the minimal card dict that get_card_embeds() expects, matching the
shape returned by the Paper Dynasty API (nested player / team / rarity).
@ -78,12 +86,14 @@ def _db_get_side_effect(evo_response):
Build a db_get coroutine side-effect that returns evo_response for
evolution/* endpoints and an empty paperdex for everything else.
"""
async def _side_effect(endpoint, **kwargs):
if "evolution" in endpoint:
return evo_response
if "paperdex" in endpoint:
return EMPTY_PAPERDEX
return None
return _side_effect
@ -91,6 +101,7 @@ def _db_get_side_effect(evo_response):
# Tier badge format — pure function tests (no Discord/API involved)
# ---------------------------------------------------------------------------
class TestTierBadgeFormat:
"""
Unit tests for the _get_tier_badge() helper that computes the badge string.
@ -137,6 +148,7 @@ class TestTierBadgeFormat:
# Integration-style tests for get_card_embeds() title construction
# ---------------------------------------------------------------------------
class TestCardEmbedTierBadge:
"""
Validates that get_card_embeds() produces the correct title format when
@ -146,6 +158,8 @@ class TestCardEmbedTierBadge:
returns, then call get_card_embeds() and inspect the resulting embed title.
"""
@pytest.mark.asyncio
@pytest.mark.asyncio
async def test_no_evolution_state_shows_plain_name(self):
"""
When the evolution API returns None (404 or down), the embed title
@ -154,13 +168,15 @@ class TestCardEmbedTierBadge:
from helpers.main import get_card_embeds
card = make_card(p_name="Mike Trout")
with patch("helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(None))):
with patch(
"helpers.main.db_get", new=AsyncMock(side_effect=_db_get_side_effect(None))
):
embeds = await get_card_embeds(card)
assert len(embeds) > 0
assert embeds[0].title == "Mike Trout"
@pytest.mark.asyncio
async def test_tier_0_shows_plain_name(self):
"""
Tier 0 in the evolution state means no progress yet no badge shown.
@ -168,56 +184,71 @@ class TestCardEmbedTierBadge:
from helpers.main import get_card_embeds
card = make_card(p_name="Mike Trout")
with patch("helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(0)))):
with patch(
"helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(0))),
):
embeds = await get_card_embeds(card)
assert embeds[0].title == "Mike Trout"
@pytest.mark.asyncio
async def test_tier_1_badge_in_title(self):
"""Tier 1 card shows [T1] prefix in the embed title."""
from helpers.main import get_card_embeds
card = make_card(p_name="Mike Trout")
with patch("helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(1)))):
with patch(
"helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(1))),
):
embeds = await get_card_embeds(card)
assert embeds[0].title == "[T1] Mike Trout"
@pytest.mark.asyncio
async def test_tier_2_badge_in_title(self):
"""Tier 2 card shows [T2] prefix in the embed title."""
from helpers.main import get_card_embeds
card = make_card(p_name="Mike Trout")
with patch("helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(2)))):
with patch(
"helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(2))),
):
embeds = await get_card_embeds(card)
assert embeds[0].title == "[T2] Mike Trout"
@pytest.mark.asyncio
async def test_tier_3_badge_in_title(self):
"""Tier 3 card shows [T3] prefix in the embed title."""
from helpers.main import get_card_embeds
card = make_card(p_name="Mike Trout")
with patch("helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(3)))):
with patch(
"helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(3))),
):
embeds = await get_card_embeds(card)
assert embeds[0].title == "[T3] Mike Trout"
@pytest.mark.asyncio
async def test_tier_4_shows_evo_badge(self):
"""Fully evolved card (tier 4) shows [EVO] prefix instead of [T4]."""
from helpers.main import get_card_embeds
card = make_card(p_name="Mike Trout")
with patch("helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(4)))):
with patch(
"helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(4))),
):
embeds = await get_card_embeds(card)
assert embeds[0].title == "[EVO] Mike Trout"
@pytest.mark.asyncio
async def test_embed_color_unchanged_by_badge(self):
"""
The tier badge must not affect the embed color rarity color is the
@ -230,13 +261,16 @@ class TestCardEmbedTierBadge:
rarity_color = "FFD700"
card = make_card(p_name="Mike Trout", rarity_color=rarity_color)
with patch("helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(3)))):
with patch(
"helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect(make_evo_state(3))),
):
embeds = await get_card_embeds(card)
expected_color = int(rarity_color, 16)
assert embeds[0].colour.value == expected_color
@pytest.mark.asyncio
async def test_evolution_api_exception_shows_plain_name(self):
"""
When the evolution API raises an unexpected exception (network error,
@ -255,12 +289,14 @@ class TestCardEmbedTierBadge:
return None
card = make_card(p_name="Mike Trout")
with patch("helpers.main.db_get",
new=AsyncMock(side_effect=exploding_side_effect)):
with patch(
"helpers.main.db_get", new=AsyncMock(side_effect=exploding_side_effect)
):
embeds = await get_card_embeds(card)
assert embeds[0].title == "Mike Trout"
@pytest.mark.asyncio
async def test_evolution_api_missing_current_tier_key(self):
"""
If the evolution response is present but lacks 'current_tier', the
@ -270,8 +306,10 @@ class TestCardEmbedTierBadge:
card = make_card(p_name="Mike Trout")
# Response exists but is missing the expected key
with patch("helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect({"xp": 50}))):
with patch(
"helpers.main.db_get",
new=AsyncMock(side_effect=_db_get_side_effect({"xp": 50})),
):
embeds = await get_card_embeds(card)
assert embeds[0].title == "Mike Trout"