You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that AsyncMlb is in place, I want a small live test suite that proves the sync and async clients both work against the real MLB Stats API.
The goal is not broad endpoint coverage. This is just enough live testing to catch problems that deterministic tests cannot, like a bad endpoint path or request shape.
The tests themselves are clean, minimal, and match the stated goal — small, stable assertions (isinstance, known ID, schedule.dates truthy), a fixed historical date (2022-10-07) to avoid "today has no games" flakiness, and no new test dependency (manual asyncio.run() instead of pulling in pytest-asyncio). Good match to the existing Mlb()/AsyncMlb() context-manager patterns already used elsewhere in the repo.
One real issue: this will break the scheduled "External MLB API Tests" workflow.
.github/workflows/external-tests.yml:29 installs deps with plain poetry install --no-interaction (no -E async), then runs pytest tests/external_tests/ -v (.github/workflows/external-tests.yml:33). That directory now includes tests/external_tests/async_mlb/test_async_mlb_smoke.py, which does from mlbstatsapi import AsyncMlb at module scope.
AsyncMlb is lazily resolved via mlbstatsapi/__init__.py's __getattr__, which imports mlbstatsapi/async_mlb.py → mlbstatsapi/async_mlb_dataadapter.py, and that module calls import_httpx() at module load time (mlbstatsapi/async_mlb_dataadapter.py:30). Since httpx is an optional extra (pyproject.toml) and isn't installed by this workflow, that import raises ImportError at collection time, e.g.:
Async support requires the optional HTTPX dependency, which is not installed. Install it with:
pip install "python-mlb-statsapi[async]"
This wasn't a problem before because nothing under tests/external_tests/ imported AsyncMlb. Compare with build-and-test.yml, which correctly installs -E async before running the offline suite. The fix is to add -E async to the poetry install step in .github/workflows/external-tests.yml:29 so the scheduled live-test run can collect the new async file. Fix this →
Minor/optional:
tests/external_tests/mlb/test_mlb_smoke.py and tests/external_tests/async_mlb/test_async_mlb_smoke.py aren't run in the offline CI (build-and-test.yml excludes tests/external_tests), so this only ever executes locally or via the weekly scheduled workflow — worth confirming that's the intended coverage story once the extras fix above lands.
No changes were implemented — this was a review-only request.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Now that
AsyncMlbis in place, I want a small live test suite that proves the sync and async clients both work against the real MLB Stats API.The goal is not broad endpoint coverage. This is just enough live testing to catch problems that deterministic tests cannot, like a bad endpoint path or request shape.
Closes #318
What
Added matching live smoke tests for the initial shared endpoints:
get_teamget_personget_scheduleThere are three sync tests using
Mlband three matching async tests usingAsyncMlb.The assertions are intentionally small and only check stable behavior like the returned model type, known IDs, and whether a schedule contains dates.
These tests stay under
tests/external_tests/and are not part of normal offline CI.Tests
Live tests can be run with: