This document describes the testing strategy and coverage for the Good First Issues project. We use pytest as our testing framework and aim to maintain 100% test coverage across all components.
Current coverage status (as of latest update):
Name Stmts Miss Cover
-----------------------------------------------------
app/__init__.py 0 0 100%
app/core/__init__.py 0 0 100%
app/core/api_handler.py 112 0 100%
app/core/config.py 12 0 100%
app/core/custom_exceptions.py 11 0 100%
app/tests/__init__.py 0 0 100%
app/tests/conftest.py 10 0 100%
app/tests/test_api_handler.py 164 0 100%
app/tests/test_update_issues.py 54 0 100%
app/update_issues.py 34 0 100%
-----------------------------------------------------
TOTAL 397 0 100%
test_extract_number_of_repos: Tests successful repository count extractiontest_extract_repos: Tests repository list extraction with paginationtest_extract_number_of_repos_error: Tests error handling for missing datatest_extract_repos_error: Tests error handling for invalid responses
test_extract_issue_data: Tests issue data extraction and formattingtest_extract_language: Tests repository language detectiontest_extract_issues: Tests issue extraction with labels- Error handling tests for each method
test_utils_divide_and_round_up: Tests pagination calculationtest_utils_create_list_from_lists: Tests list flattening functionality
test_apiclient_make_request_success: Tests successful API requeststest_apiclient_make_request_error: Tests HTTP error handlingtest_apiclient_make_request_general_error: Tests general error handling
test_format_response: Tests issue grouping by languagetest_render_template: Tests template rendering with Jinja2
test_main_flow: Tests the complete workflowtest_main_with_no_repos: Tests behavior with no repositoriestest_main_with_no_issues: Tests behavior with no issuestest_main_script_execution: Tests script runtime measurement
To run the test suite:
python -m pytest app/tests/ -v --cov=appFor detailed coverage report:
python -m pytest app/tests/ -v --cov=app --cov-report term-missingKey fixtures (defined in conftest.py):
mock_session: Mocks requests.Session for API callsmock_env_vars: Sets up environment variables for testing
We test various error scenarios:
- API errors (404, rate limits, etc.)
- Missing or malformed data
- File system errors
- Environment configuration errors
When adding new features:
- Maintain 100% coverage for new code
- Add tests for both success and error cases
- Mock external dependencies
- Test edge cases and boundary conditions
When modifying existing code:
- Run the test suite to ensure no regressions
- Update tests if behavior changes
- Add new test cases for bug fixes
- API Mocking:
@patch('app.core.api_handler.APIClient')
def test_function(self, mock_api_client):
mock_api_instance = MagicMock()
mock_api_client.return_value = mock_api_instance
# Test implementation- File Operations:
def test_file_operations(self, tmp_path):
# Use tmp_path for temporary file creation
temp_file = tmp_path / "test.txt"
# Test implementation- Error Handling:
with pytest.raises(ExpectedError):
# Code that should raise ExpectedError