Add pytest test suite with mocked GitHub API responses - #3
Merged
Conversation
Sets up a tests/ package with conftest.py fixtures (MockResponse helper, mock_requests patch, mock_sleep patch) and 9 focused tests covering: - wait_for_rate_limit with X-RateLimit-Reset header and no-header fallback - fetch_page success, 403 retry, 422 rejection, 500 rejection - requests.exceptions.Timeout and ConnectionError retry logic - Full crawl_github_algorithm_issues output-file production Dev dependency group [dev] with pytest>=8 added to pyproject.toml. Install with: pip install -e ".[dev]"
Vedant-code
approved these changes
Jul 7, 2026
Vedant-code
left a comment
Owner
There was a problem hiding this comment.
It's a solid foundation that addresses the "zero tests" problem. Great work. However, it leaves some important paths untested (global state management, _check_rate_limit_before_request, retry-after header).
I am opening a follow-up issue to add the missing tests (especially the global state reset and _check_rate_limit_before_request.
10 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Sets up a proper test harness for the GitHub search crawler. Zero tests was the biggest quality gap — this adds 9 focused tests covering the core
wait_for_rate_limit,fetch_page, andcrawl_github_algorithm_issuesfunctions.What was added
tests/conftest.py— shared fixturesMockResponse— builds a mockrequests.Responsewith the shape the code expects (status_code, headers, json(), text)make_search_result()— builds GitHub Search API result bodiesmock_requestsfixture — patchesrequests.getwith configurable return valuemock_sleepfixture — patchestime.sleepto a no-op so tests finish in ~0.1s instead of minutesempty_env/success_responsefixtures for common setupstests/test_main.py— 9 tests covering:test_uses_reset_tswait_for_rate_limitsleeps untilX-RateLimit-Resettest_fallback_60stest_success_returns_responsetest_403_calls_wait_and_retriestest_422_returns_nonetest_unexpected_status_returns_nonetest_timeout_retriesrequests.exceptions.Timeoutcaught and retriedtest_max_retries_exceededtest_produces_output_fileresults.mdpyproject.toml— added[dev]optional dependency group withpytest>=8and[tool.pytest.ini_options].Running
pip install -e ".[dev]" pytest tests/ -vDesign choices
pytestitself. Usesunittest.mock(stdlib), nopytest-mockorresponsesneeded.time.sleepis patched — rate-limit tests would take minutes of wall time otherwise. Withmock_sleepthey finish instantly.