fix: add @pytest.mark.asyncio to async test methods (#21)
Closes #21 All 14 async test methods in tests/test_automated_data_fetcher.py were missing @pytest.mark.asyncio. Without it, pytest collects them and silently passes without executing the coroutine body, providing no coverage. Added explicit @pytest.mark.asyncio to each async def test_* method. This makes the async intent unambiguous and is robust against any future asyncio_mode configuration changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f1ca14791d
commit
ee4dae0985
@ -170,6 +170,7 @@ class TestDataFetcher:
|
|||||||
|
|
||||||
@patch("automated_data_fetcher.pb.batting_stats_bref")
|
@patch("automated_data_fetcher.pb.batting_stats_bref")
|
||||||
@patch("automated_data_fetcher.pb.pitching_stats_bref")
|
@patch("automated_data_fetcher.pb.pitching_stats_bref")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_baseball_reference_data(
|
async def test_fetch_baseball_reference_data(
|
||||||
self,
|
self,
|
||||||
mock_pitching,
|
mock_pitching,
|
||||||
@ -206,6 +207,7 @@ class TestDataFetcher:
|
|||||||
|
|
||||||
@patch("automated_data_fetcher.pb.batting_stats")
|
@patch("automated_data_fetcher.pb.batting_stats")
|
||||||
@patch("automated_data_fetcher.pb.pitching_stats")
|
@patch("automated_data_fetcher.pb.pitching_stats")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_fangraphs_data(
|
async def test_fetch_fangraphs_data(
|
||||||
self,
|
self,
|
||||||
mock_pitching,
|
mock_pitching,
|
||||||
@ -231,6 +233,7 @@ class TestDataFetcher:
|
|||||||
|
|
||||||
@patch("automated_data_fetcher.pb.batting_stats_range")
|
@patch("automated_data_fetcher.pb.batting_stats_range")
|
||||||
@patch("automated_data_fetcher.pb.pitching_stats_range")
|
@patch("automated_data_fetcher.pb.pitching_stats_range")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_fangraphs_data_with_dates(
|
async def test_fetch_fangraphs_data_with_dates(
|
||||||
self,
|
self,
|
||||||
mock_pitching,
|
mock_pitching,
|
||||||
@ -253,6 +256,7 @@ class TestDataFetcher:
|
|||||||
mock_pitching.assert_called_once_with(start_date, end_date)
|
mock_pitching.assert_called_once_with(start_date, end_date)
|
||||||
|
|
||||||
@patch("automated_data_fetcher.get_all_pybaseball_ids")
|
@patch("automated_data_fetcher.get_all_pybaseball_ids")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_get_active_players_existing_function(self, mock_get_ids, fetcher):
|
async def test_get_active_players_existing_function(self, mock_get_ids, fetcher):
|
||||||
"""Test getting player IDs using existing function"""
|
"""Test getting player IDs using existing function"""
|
||||||
mock_get_ids.return_value = ["12345", "67890", "11111"]
|
mock_get_ids.return_value = ["12345", "67890", "11111"]
|
||||||
@ -264,6 +268,7 @@ class TestDataFetcher:
|
|||||||
|
|
||||||
@patch("automated_data_fetcher.get_all_pybaseball_ids")
|
@patch("automated_data_fetcher.get_all_pybaseball_ids")
|
||||||
@patch("automated_data_fetcher.pb.batting_stats")
|
@patch("automated_data_fetcher.pb.batting_stats")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_get_active_players_fallback(
|
async def test_get_active_players_fallback(
|
||||||
self, mock_batting, mock_get_ids, fetcher, sample_batting_data
|
self, mock_batting, mock_get_ids, fetcher, sample_batting_data
|
||||||
):
|
):
|
||||||
@ -279,6 +284,7 @@ class TestDataFetcher:
|
|||||||
assert result == expected_ids
|
assert result == expected_ids
|
||||||
|
|
||||||
@patch("automated_data_fetcher.pb.get_splits")
|
@patch("automated_data_fetcher.pb.get_splits")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_player_splits(
|
async def test_fetch_player_splits(
|
||||||
self, mock_get_splits, fetcher, sample_splits_data
|
self, mock_get_splits, fetcher, sample_splits_data
|
||||||
):
|
):
|
||||||
@ -333,6 +339,7 @@ class TestLiveSeriesDataFetcher:
|
|||||||
|
|
||||||
@patch.object(DataFetcher, "fetch_baseball_reference_data")
|
@patch.object(DataFetcher, "fetch_baseball_reference_data")
|
||||||
@patch.object(DataFetcher, "fetch_fangraphs_data")
|
@patch.object(DataFetcher, "fetch_fangraphs_data")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_live_data(self, mock_fg_data, mock_bref_data, live_fetcher):
|
async def test_fetch_live_data(self, mock_fg_data, mock_bref_data, live_fetcher):
|
||||||
"""Test fetching live series data"""
|
"""Test fetching live series data"""
|
||||||
# Mock return values
|
# Mock return values
|
||||||
@ -360,6 +367,7 @@ class TestUtilityFunctions:
|
|||||||
"""Test cases for utility functions"""
|
"""Test cases for utility functions"""
|
||||||
|
|
||||||
@patch("automated_data_fetcher.DataFetcher")
|
@patch("automated_data_fetcher.DataFetcher")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_season_data(self, mock_fetcher_class):
|
async def test_fetch_season_data(self, mock_fetcher_class):
|
||||||
"""Test fetch_season_data function"""
|
"""Test fetch_season_data function"""
|
||||||
# Create mock fetcher instance
|
# Create mock fetcher instance
|
||||||
@ -389,6 +397,7 @@ class TestUtilityFunctions:
|
|||||||
assert any("AUTOMATED DOWNLOAD COMPLETE" in call for call in print_calls)
|
assert any("AUTOMATED DOWNLOAD COMPLETE" in call for call in print_calls)
|
||||||
|
|
||||||
@patch("automated_data_fetcher.LiveSeriesDataFetcher")
|
@patch("automated_data_fetcher.LiveSeriesDataFetcher")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_live_series_data(self, mock_fetcher_class):
|
async def test_fetch_live_series_data(self, mock_fetcher_class):
|
||||||
"""Test fetch_live_series_data function"""
|
"""Test fetch_live_series_data function"""
|
||||||
# Create mock fetcher instance
|
# Create mock fetcher instance
|
||||||
@ -416,6 +425,7 @@ class TestErrorHandling:
|
|||||||
return DataFetcher(2023, "Season")
|
return DataFetcher(2023, "Season")
|
||||||
|
|
||||||
@patch("automated_data_fetcher.pb.pitching_stats_bref")
|
@patch("automated_data_fetcher.pb.pitching_stats_bref")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_baseball_reference_data_error(self, mock_pitching, fetcher):
|
async def test_fetch_baseball_reference_data_error(self, mock_pitching, fetcher):
|
||||||
"""Test error handling in Baseball Reference data fetch"""
|
"""Test error handling in Baseball Reference data fetch"""
|
||||||
# Mock function to raise an exception
|
# Mock function to raise an exception
|
||||||
@ -425,6 +435,7 @@ class TestErrorHandling:
|
|||||||
await fetcher.fetch_baseball_reference_data()
|
await fetcher.fetch_baseball_reference_data()
|
||||||
|
|
||||||
@patch("automated_data_fetcher.pb.batting_stats")
|
@patch("automated_data_fetcher.pb.batting_stats")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_fangraphs_data_error(self, mock_batting, fetcher):
|
async def test_fetch_fangraphs_data_error(self, mock_batting, fetcher):
|
||||||
"""Test error handling in FanGraphs data fetch"""
|
"""Test error handling in FanGraphs data fetch"""
|
||||||
# Mock function to raise an exception
|
# Mock function to raise an exception
|
||||||
@ -435,6 +446,7 @@ class TestErrorHandling:
|
|||||||
|
|
||||||
@patch("automated_data_fetcher.get_all_pybaseball_ids")
|
@patch("automated_data_fetcher.get_all_pybaseball_ids")
|
||||||
@patch("automated_data_fetcher.pb.batting_stats")
|
@patch("automated_data_fetcher.pb.batting_stats")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_get_active_players_complete_failure(
|
async def test_get_active_players_complete_failure(
|
||||||
self, mock_batting, mock_get_ids, fetcher
|
self, mock_batting, mock_get_ids, fetcher
|
||||||
):
|
):
|
||||||
@ -449,6 +461,7 @@ class TestErrorHandling:
|
|||||||
assert result == []
|
assert result == []
|
||||||
|
|
||||||
@patch("automated_data_fetcher.pb.get_splits")
|
@patch("automated_data_fetcher.pb.get_splits")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_fetch_player_splits_individual_errors(
|
async def test_fetch_player_splits_individual_errors(
|
||||||
self, mock_get_splits, fetcher
|
self, mock_get_splits, fetcher
|
||||||
):
|
):
|
||||||
@ -479,6 +492,7 @@ class TestIntegration:
|
|||||||
"""Integration tests that require network access"""
|
"""Integration tests that require network access"""
|
||||||
|
|
||||||
@pytest.mark.skip(reason="Requires network access and may be slow")
|
@pytest.mark.skip(reason="Requires network access and may be slow")
|
||||||
|
@pytest.mark.asyncio
|
||||||
async def test_real_data_fetch(self):
|
async def test_real_data_fetch(self):
|
||||||
"""Test fetching real data from pybaseball (skip by default)"""
|
"""Test fetching real data from pybaseball (skip by default)"""
|
||||||
fetcher = DataFetcher(2022, "Season") # Use a complete season
|
fetcher = DataFetcher(2022, "Season") # Use a complete season
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user