FBCM Testing Strategy¶
Current State¶
Modules With Tests (8/18 source modules)¶
| Module | Test File | Coverage Level |
|---|---|---|
metadata.py (functions) |
test_base.py |
High — playoff conversion, week parsing |
config.py |
test_config.py |
High — all from_cli_and_config paths |
browser_retry.py |
test_browser_retry.py |
High — retry logic, error recovery |
file_namer.py |
test_file_namer.py |
High — NFL/NCAA/Series naming |
constants.py |
test_constants.py |
Basic validation |
utils.py |
test_utils.py |
generate_episode_metadata_xml |
logging_config.py |
test_logging_config.py |
setup_logging |
parsers/* |
test_parsers/* |
High — all 5 parsers with HTML fixtures |
Modules Without Tests¶
| Module | LOC | Risk | Testability |
|---|---|---|---|
models.py |
393 | HIGH | Excellent — pure dataclasses, no I/O |
draft_buzz.py |
409 | HIGH | Mixed — static methods testable, browser logic needs mocks |
docx/word_gen.py |
920 | HIGH | Mixed — helpers testable, DOCX generation needs fixtures |
file_operations.py |
234 | HIGH | Good — filesystem ops mockable with tmp_path |
nfl.py |
499 | HIGH | Good — injectable deps, mockable API client |
metadata.py (MetaDataCreator) |
137 | MEDIUM | Good — filesystem + string logic |
mcmillen.py |
30 | MEDIUM | Good — mock requests |
downloaders/base_downloader.py |
100 | MEDIUM | Low — yt-dlp wrapper |
fbcm.py (CLI) |
626 | LOW | Can use Click's CliRunner |
Testing Strategy¶
Framework & Tools¶
- pytest (already in use) — test runner and fixtures
- pytest-cov — coverage reporting (added as dev dependency)
- unittest.mock — mocking external dependencies (Playwright, requests, ffmpeg, yt-dlp)
- tmp_path — pytest built-in fixture for filesystem tests
- HTML fixtures — already established pattern in
tests/test_fbcm/test_parsers/conftest.py
Testing Approach by Module Category¶
1. Pure Logic (Unit Tests — No Mocking Required)¶
These modules have no external dependencies and can be tested directly:
models.py—from_dict(),to_dict(),_convert_value(), position-aware type resolutiondocx/word_gen.pyhelpers —blend_colors(),darken_color(),hex_to_rgb(),skill_bar(),get_primary_position()metadata.pyMetaDataCreator._create_title_string()
2. I/O-Dependent (Mock External Dependencies)¶
file_operations.py— Usetmp_pathfor filesystem, mockmutagen.mp4.MP4andffmpegnfl.py— MockGriddyNFLclient, use injectable collaboratorsdraft_buzz.py— Mock Playwright browser/page objects, test parsing orchestration with HTML fixturesmcmillen.py— Mockrequests.get, test HTML parsing with fixture strings
3. Integration-Heavy (Defer or Mark as @pytest.mark.integration)¶
fbcm.pyCLI commands — Click'sCliRunnerfor smoke testsdownloaders/base_downloader.py— yt-dlp wrapper, low value to unit testdocx/word_gen.pyDOCX generation — complex document rendering, consider golden-file approach later
Fixture Strategy¶
- HTML fixtures: Continue the established pattern in
conftest.pyfor parser and scraper tests - Factory fixtures: Use
@pytest.fixturefactories (like existingmake_soup) for creating test data - Model fixtures: Create reusable prospect data fixtures for
word_gen.pyanddraft_buzz.pytests - tmp_path: Use pytest's built-in
tmp_pathfor all filesystem operations
Coverage Target¶
Given the I/O-heavy nature of the codebase:
- Target: 70% line coverage as initial goal
- Pure logic modules: Target 90%+ (models, helpers, metadata functions)
- I/O modules: Target 60%+ (mock boundaries, test business logic)
- CLI/integration: Defer to future tickets, mark with
@pytest.mark.integration
Snapshot/Golden-File Testing¶
Not recommended at this stage. The parsers already use HTML fixture strings effectively. Golden-file testing could be considered later for DOCX output validation if visual regression becomes a concern.
Browser-Dependent Tests¶
- Mock Playwright objects (
Browser,Page,Locator) for unit tests - Static methods in
PageFetcher(_make_absolute_url,_get_image_type,_should_skip_image) are testable without mocks - Full browser integration tests should be marked
@pytest.mark.integrationand@pytest.mark.slow
Pytest Configuration¶
The following additions were made to pyproject.toml:
pytest-covadded to dev dependencies- Coverage configuration updated with
--covflags inaddopts - Coverage report configured with
fail_underthreshold
Priority Order for Test Implementation¶
models.py— Used everywhere, pure logic, highest ROIdocx/word_gen.pyhelpers — Pure functions, easy winsfile_operations.py— Safety-critical filesystem operationsnfl.py(GameExtractor,MetadataWriter) — Core business logicmetadata.py(MetaDataCreator) — String construction + filesystemdraft_buzz.py(static methods +ProspectParser) — Scraping orchestrationmcmillen.py— Small module, quick to cover