Fix test fixture to not interfere with other tests
This commit is contained in:
parent
20f33f45e1
commit
e00591b6bf
1 changed files with 12 additions and 10 deletions
|
|
@ -40,16 +40,18 @@ async def dummy_handler(player, args):
|
|||
await player.writer.drain()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@pytest.fixture
|
||||
def clean_registry():
|
||||
"""Clear registry before each test."""
|
||||
original_registry = commands._registry.copy()
|
||||
commands._registry.clear()
|
||||
yield
|
||||
commands._registry.clear()
|
||||
commands._registry.update(original_registry)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_exact_match_still_works(player):
|
||||
async def test_exact_match_still_works(player, clean_registry):
|
||||
"""Test that exact matches work as before."""
|
||||
commands.register(
|
||||
CommandDefinition(name="look", handler=dummy_handler, mode="normal")
|
||||
|
|
@ -63,7 +65,7 @@ async def test_exact_match_still_works(player):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_prefix_match_resolves_unique_prefix(player):
|
||||
async def test_prefix_match_resolves_unique_prefix(player, clean_registry):
|
||||
"""Test that a unique prefix resolves to the full command."""
|
||||
commands.register(
|
||||
CommandDefinition(name="sweep", handler=dummy_handler, mode="normal")
|
||||
|
|
@ -77,7 +79,7 @@ async def test_prefix_match_resolves_unique_prefix(player):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ambiguous_prefix_two_matches(player):
|
||||
async def test_ambiguous_prefix_two_matches(player, clean_registry):
|
||||
"""Test that ambiguous prefix with 2 matches shows 'A or B?' message."""
|
||||
commands.register(
|
||||
CommandDefinition(name="swoop", handler=dummy_handler, mode="normal")
|
||||
|
|
@ -95,7 +97,7 @@ async def test_ambiguous_prefix_two_matches(player):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ambiguous_prefix_three_plus_matches(player):
|
||||
async def test_ambiguous_prefix_three_plus_matches(player, clean_registry):
|
||||
"""Test that ambiguous prefix with 3+ matches shows comma-separated."""
|
||||
commands.register(
|
||||
CommandDefinition(name="send", handler=dummy_handler, mode="normal")
|
||||
|
|
@ -119,7 +121,7 @@ async def test_ambiguous_prefix_three_plus_matches(player):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_no_match_shows_unknown_command(player):
|
||||
async def test_no_match_shows_unknown_command(player, clean_registry):
|
||||
"""Test that no match shows unknown command message."""
|
||||
commands.register(
|
||||
CommandDefinition(name="look", handler=dummy_handler, mode="normal")
|
||||
|
|
@ -133,7 +135,7 @@ async def test_no_match_shows_unknown_command(player):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_exact_alias_match_wins_over_prefix(player):
|
||||
async def test_exact_alias_match_wins_over_prefix(player, clean_registry):
|
||||
"""Test that exact match on alias takes priority over prefix match."""
|
||||
commands.register(
|
||||
CommandDefinition(
|
||||
|
|
@ -156,7 +158,7 @@ async def test_exact_alias_match_wins_over_prefix(player):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_single_char_ambiguous_prefix(player):
|
||||
async def test_single_char_ambiguous_prefix(player, clean_registry):
|
||||
"""Test that single-char ambiguous prefix shows disambiguation."""
|
||||
commands.register(
|
||||
CommandDefinition(name="quit", handler=dummy_handler, mode="normal")
|
||||
|
|
@ -173,7 +175,7 @@ async def test_single_char_ambiguous_prefix(player):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_prefix_match_deduplicates_aliases(player):
|
||||
async def test_prefix_match_deduplicates_aliases(player, clean_registry):
|
||||
"""Test that aliases to the same command don't create multiple matches."""
|
||||
commands.register(
|
||||
CommandDefinition(
|
||||
|
|
@ -201,7 +203,7 @@ async def test_prefix_match_deduplicates_aliases(player):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_prefix_match_with_args(player):
|
||||
async def test_prefix_match_with_args(player, clean_registry):
|
||||
"""Test that prefix matching preserves arguments."""
|
||||
commands.register(
|
||||
CommandDefinition(name="sweep", handler=dummy_handler, mode="normal")
|
||||
|
|
|
|||
Loading…
Reference in a new issue