{"id":15654333,"url":"https://github.com/idlesign/pytest-responsemock","last_synced_at":"2025-04-30T22:49:36.690Z","repository":{"id":43287358,"uuid":"245155608","full_name":"idlesign/pytest-responsemock","owner":"idlesign","description":"Simplified requests calls mocking for pytest","archived":false,"fork":false,"pushed_at":"2023-04-28T01:38:44.000Z","size":48,"stargazers_count":27,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-30T22:49:28.571Z","etag":null,"topics":["mock","mocking","pytest","pytest-plugin","python","python3","requests","responses"],"latest_commit_sha":null,"homepage":"https://github.com/idlesign/pytest-responsemock","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idlesign.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG","contributing":"CONTRIBUTING","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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-05T12:19:52.000Z","updated_at":"2023-04-19T11:08:16.000Z","dependencies_parsed_at":"2024-10-23T03:49:04.982Z","dependency_job_id":"c40aa11d-f1af-4b5c-9250-a6b2b3c392cd","html_url":"https://github.com/idlesign/pytest-responsemock","commit_stats":{"total_commits":30,"total_committers":1,"mean_commits":30.0,"dds":0.0,"last_synced_commit":"91d55f2a9548878534b7eec3cf40038c26179e10"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idlesign%2Fpytest-responsemock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idlesign%2Fpytest-responsemock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idlesign%2Fpytest-responsemock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idlesign%2Fpytest-responsemock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idlesign","download_url":"https://codeload.github.com/idlesign/pytest-responsemock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251795387,"owners_count":21645019,"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":["mock","mocking","pytest","pytest-plugin","python","python3","requests","responses"],"created_at":"2024-10-03T12:50:49.652Z","updated_at":"2025-04-30T22:49:36.666Z","avatar_url":"https://github.com/idlesign.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pytest-responsemock\n===================\nhttps://github.com/idlesign/pytest-responsemock\n\n|release| |lic| |coverage|\n\n.. |release| image:: https://img.shields.io/pypi/v/pytest-responsemock.svg\n    :target: https://pypi.python.org/pypi/pytest-responsemock\n\n.. |lic| image:: https://img.shields.io/pypi/l/pytest-responsemock.svg\n    :target: https://pypi.python.org/pypi/pytest-responsemock\n\n.. |coverage| image:: https://img.shields.io/coveralls/idlesign/pytest-responsemock/master.svg\n    :target: https://coveralls.io/r/idlesign/pytest-responsemock\n\n\nDescription\n-----------\n\n*Simplified requests calls mocking for pytest*\n\nProvides ``response_mock`` fixture, exposing simple context manager.\n\nAny request under that manager will be intercepted and mocked according\nto one or more ``rules`` passed to the manager. If actual request won't fall\nunder any of given rules then an exception is raised (by default).\n\nRules are simple strings, of the pattern: ``HTTP_METHOD URL -\u003e STATUS_CODE :BODY``.\n\n\nRequirements\n------------\n\n* Python 3.7+\n\n\nUsage\n-----\n\nWhen this package is installed ``response_mock`` is available for ``pytest`` test functions.\n\n.. code-block:: python\n\n    def for_test():\n        return requests.get('http://some.domain')\n\n\n    def test_me(response_mock):\n\n        # Pass response rule as a string,\n        # or many rules (to mock consequent requests) as a list of strings/bytes.\n        # Use optional `bypass` argument to disable mock conditionally.\n\n        with response_mock('GET http://some.domain -\u003e 200 :Nice', bypass=False):\n\n            result = for_test()\n\n            assert result.ok\n            assert result.content == b'Nice'\n            \n        # mock consequent requests\n        with response_mock([\n            'GET http://some.domain -\u003e 200 :Nice',\n            'GET http://other.domain -\u003e 200 :Sweet',\n        ]):\n            for_test()\n            requests.get('http://other.domain')\n\n\nUse with ``pytest-datafixtures``:\n\n.. code-block:: python\n\n    def test_me(response_mock, datafix_read):\n\n        with response_mock(f\"GET http://some.domain -\u003e 200 :{datafix_read('myresponse.html')}\"):\n            ...\n\n\nDescribe response header fields using multiline strings:\n\n.. code-block:: python\n\n    with response_mock(\n        '''\n        GET http://some.domain\n\n        Allow: GET, HEAD\n        Content-Language: ru\n\n        -\u003e 200 :OK\n        '''\n    ):\n        ...\n\nTest json response:\n\n.. code-block:: python\n\n    response = json.dumps({'key': 'value', 'another': 'yes'})\n\n    with response_mock(f'POST http://some.domain -\u003e 400 :{response}'):\n        ...\n\nTo test binary response pass rule as bytes:\n\n.. code-block:: python\n\n    with response_mock(b'GET http://some.domain -\u003e 200 :' + my_bytes):\n        ...\n\nAccess underlying RequestsMock (from ``responses`` package) as ``mock``:\n\n.. code-block:: python\n\n    with response_mock('HEAD http://some.domain -\u003e 200 :Nope') as mock:\n\n        mock.add_passthru('http://other.domain')\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidlesign%2Fpytest-responsemock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidlesign%2Fpytest-responsemock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidlesign%2Fpytest-responsemock/lists"}