* feat: enhance coverage reporting and improve tool configuration - Added support for JSON coverage reports in pyproject.toml. - Updated .gitignore to include coverage.json and task files for better management. - Introduced a new Type Safety Audit Report to document findings and recommendations for type safety improvements. - Created a comprehensive coverage configuration guide to assist in understanding coverage reporting setup. - Refactored tools configuration to utilize environment variables for concurrent scraping settings. These changes improve the project's testing and reporting capabilities while enhancing overall code quality and maintainability. * feat: enhance configuration handling and improve error logging - Introduced a new utility function `_get_env_int` for robust environment variable integer retrieval with validation. - Updated `WebToolsConfig` and `ToolsConfigModel` to utilize the new utility for environment variable defaults. - Enhanced logging in `CircuitBreaker` to provide detailed state transition information. - Improved URL handling in `url_analyzer.py` for better file extension extraction and normalization. - Added type validation and logging in `SecureInputMixin` to ensure input sanitization and validation consistency. These changes improve the reliability and maintainability of configuration management and error handling across the codebase. * refactor: update imports and enhance .gitignore for improved organization - Updated import paths in various example scripts to reflect the new structure under `biz_bud`. - Enhanced .gitignore to include clearer formatting for task files. - Removed obsolete function calls and improved error handling in several scripts. - Added public alias for backward compatibility in `upload_r2r.py`. These changes improve code organization, maintainability, and compatibility across the project. * refactor: update graph paths in langgraph.json for improved organization - Changed paths for research, catalog, paperless, and url_to_r2r graphs to reflect new directory structure. - Added new entries for analysis and scraping graphs to enhance functionality. These changes improve the organization and maintainability of the graph configurations. * fix: enhance validation and error handling in date range and scraping functions - Updated date validation in UserFiltersModel to ensure date values are strings. - Improved error messages in create_scraped_content_dict to clarify conditions for success and failure. - Enhanced test coverage for date validation and scraping content creation to ensure robustness. These changes improve input validation and error handling across the application, enhancing overall reliability. * refactor: streamline graph creation and enhance type annotations in examples - Simplified graph creation in `catalog_ingredient_research_example.py` and `catalog_tech_components_example.py` by directly compiling the graph. - Updated type annotations in `catalog_intel_with_config.py` for improved clarity and consistency. - Enhanced error handling in catalog data processing to ensure robustness against unexpected data types. These changes improve code readability, maintainability, and error resilience across example scripts. * Update src/biz_bud/nodes/extraction/extractors.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update src/biz_bud/core/validation/pydantic_models.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * refactor: migrate Jina and Tavily clients to use ServiceFactory dependency injection * refactor: migrate URL processing to provider-based architecture with improved error handling * feat: add FirecrawlApp compatibility classes and mock implementations * fix: add thread-safe locking to LazyLoader factory management * feat: implement service restart and refactor cache decorator helpers * refactor: move r2r_direct_api_call to tools.clients.r2r_utils and improve HTTP service error handling * chore: update Sonar task IDs in report configuration --------- Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
4.1 KiB
4.1 KiB
Coverage Configuration Guide
This document explains the coverage reporting configuration for the Business Buddy project.
Overview
The project uses pytest-cov for code coverage measurement with comprehensive reporting options configured in pyproject.toml.
Configuration
Coverage Collection ([tool.coverage.run])
- Source:
src/biz_bud- Measures coverage for all source code - Branch Coverage: Enabled to track both statement and branch coverage
- Parallel Execution: Supports parallel test execution with xdist
- Omitted Files:
- Test files (
*/tests/*,*/test_*.py,*/conftest.py) - Init files (
*/__init__.py) - Entry points (
webapp.py, CLI files) - Database migrations
- Test files (
Coverage Reporting ([tool.coverage.report])
- Show Missing: Displays line numbers for uncovered code
- Precision: 2 decimal places for coverage percentages
- Skip Empty: Excludes empty files from reports
- Comprehensive Exclusions:
- Type checking blocks (
if TYPE_CHECKING:) - Debug code (
if DEBUG:,if __debug__:) - Platform-specific code
- Error handling patterns
- Abstract methods and protocols
- Type checking blocks (
Report Formats
- Terminal:
--cov-report=term-missing:skip-covered - HTML:
htmlcov/index.htmlwith context information - XML:
coverage.xmlfor CI/CD integration - JSON:
coverage.jsonfor programmatic access
Usage
Running Tests with Coverage
# Run all tests with coverage
make test
# Run specific test with coverage
pytest tests/path/to/test.py --cov=src/biz_bud --cov-report=html
# Run without coverage (faster for development)
pytest tests/path/to/test.py --no-cov
Coverage Reports
# Generate HTML report
pytest --cov=src/biz_bud --cov-report=html
# View HTML report
open htmlcov/index.html # macOS
xdg-open htmlcov/index.html # Linux
# Generate XML report for CI
pytest --cov=src/biz_bud --cov-report=xml
# Generate JSON report
pytest --cov=src/biz_bud --cov-report=json
Coverage Thresholds
- Minimum Coverage: 70% (configurable via
--cov-fail-under) - Branch Coverage: Required for thorough testing
- Context Tracking: Enabled to track which tests cover which code
Best Practices
- Write Tests First: Aim for high coverage through TDD
- Focus on Critical Paths: Prioritize coverage for core business logic
- Use Exclusion Pragmas: Mark intentionally untested code with
# pragma: no cover - Review Coverage Reports: Use HTML reports to identify missed edge cases
- Monitor Trends: Track coverage changes in CI/CD
Exclusion Patterns
The configuration excludes common patterns that don't need testing:
- Type checking imports (
if TYPE_CHECKING:) - Debug statements (
if DEBUG:,if __debug__:) - Platform-specific code (
if sys.platform) - Abstract methods (
@abstract,raise NotImplementedError) - Error handling boilerplate (
except ImportError:)
Integration with CI/CD
The XML and JSON reports are designed for integration with:
- GitHub Actions: Upload coverage to services like Codecov
- SonarQube: Import coverage data for quality gates
- IDE Integration: Many IDEs can display coverage inline
Troubleshooting
Common Issues
- No Data Collected: Ensure source paths match actual file locations
- Parallel Test Issues: Coverage data may need combining with
coverage combine - Missing Files: Check that files are imported during test execution
- Low Coverage: Review exclusion patterns and test completeness
Debug Commands
# Check coverage configuration
python -m coverage debug config
# Combine parallel coverage data
python -m coverage combine
# Erase coverage data
python -m coverage erase
Files
- Configuration:
pyproject.toml([tool.coverage.*]sections) - Data File:
.coverage(temporary, in .gitignore) - HTML Reports:
htmlcov/directory (in .gitignore) - XML Report:
coverage.xml(in .gitignore) - JSON Report:
coverage.json(in .gitignore)