{"id":13502115,"url":"https://github.com/patrys/httmock","last_synced_at":"2025-05-14T19:07:18.594Z","repository":{"id":7539766,"uuid":"8891992","full_name":"patrys/httmock","owner":"patrys","description":"A mocking library for requests","archived":false,"fork":false,"pushed_at":"2023-09-29T20:58:48.000Z","size":72,"stargazers_count":466,"open_issues_count":16,"forks_count":56,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-13T13:19:50.053Z","etag":null,"topics":["http","mock","python","requests"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2013-03-19T23:35:33.000Z","updated_at":"2025-01-13T18:22:26.000Z","dependencies_parsed_at":"2024-01-29T18:51:49.444Z","dependency_job_id":null,"html_url":"https://github.com/patrys/httmock","commit_stats":{"total_commits":73,"total_committers":29,"mean_commits":"2.5172413793103448","dds":0.6164383561643836,"last_synced_commit":"98269075d0c36a0e87e2b6b7ad9c6a16622aba58"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrys%2Fhttmock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrys%2Fhttmock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrys%2Fhttmock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrys%2Fhttmock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrys","download_url":"https://codeload.github.com/patrys/httmock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","mock","python","requests"],"created_at":"2024-07-31T22:02:02.396Z","updated_at":"2025-05-14T19:07:16.674Z","avatar_url":"https://github.com/patrys.png","language":"Python","readme":"httmock\n=======\n\nA mocking library for `requests` for Python 2.7 and 3.4+.\n\nInstallation\n------------\n\n    pip install httmock\n\nOr, if you are a Gentoo user:\n\n    emerge dev-python/httmock\n\nUsage\n-----\nYou can use it to mock third-party APIs and test libraries that use `requests` internally, conditionally using mocked replies with the `urlmatch` decorator:\n\n```python\nfrom httmock import urlmatch, HTTMock\nimport requests\n\n@urlmatch(netloc=r'(.*\\.)?google\\.com$')\ndef google_mock(url, request):\n    return 'Feeling lucky, punk?'\n\nwith HTTMock(google_mock):\n    r = requests.get('http://google.com/')\nprint r.content  # 'Feeling lucky, punk?'\n```\n\nThe `all_requests` decorator doesn't conditionally block real requests. If you return a dictionary, it will map to the `requests.Response` object returned:\n\n```python\nfrom httmock import all_requests, HTTMock\nimport requests\n\n@all_requests\ndef response_content(url, request):\n\treturn {'status_code': 200,\n\t        'content': 'Oh hai'}\n\nwith HTTMock(response_content):\n\tr = requests.get('https://foo_bar')\n\nprint r.status_code\nprint r.content\n```\n\nIf you pass in `Set-Cookie` headers, `requests.Response.cookies` will contain the values. You can also use `response` method directly instead of returning a dict:\n\n```python\nfrom httmock import all_requests, response, HTTMock\nimport requests\n\n@all_requests\ndef response_content(url, request):\n\theaders = {'content-type': 'application/json',\n\t           'Set-Cookie': 'foo=bar;'}\n\tcontent = {'message': 'API rate limit exceeded'}\n\treturn response(403, content, headers, None, 5, request)\n\nwith HTTMock(response_content):\n\tr = requests.get('https://api.github.com/users/whatever')\n\nprint r.json().get('message')\nprint r.cookies['foo']\n```\n","funding_links":[],"categories":["Testing","资源列表","Python","测试","Mock and Stub","File Manipulation","Testing [🔝](#readme)","Awesome Python"],"sub_categories":["测试","HTTP Clients","Testing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrys%2Fhttmock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrys%2Fhttmock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrys%2Fhttmock/lists"}