{"id":13542184,"url":"https://github.com/kevin1024/pytest-httpbin","last_synced_at":"2025-05-15T15:01:48.751Z","repository":{"id":17753004,"uuid":"20604677","full_name":"kevin1024/pytest-httpbin","owner":"kevin1024","description":"Easily test your HTTP library against a local copy of httpbin.org","archived":false,"fork":false,"pushed_at":"2024-09-18T15:45:45.000Z","size":204,"stargazers_count":192,"open_issues_count":7,"forks_count":30,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-07T06:16:29.499Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevin1024.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,"publiccode":null,"codemeta":null}},"created_at":"2014-06-07T22:56:47.000Z","updated_at":"2025-03-12T01:04:09.000Z","dependencies_parsed_at":"2024-08-08T10:43:18.414Z","dependency_job_id":"3527ebaa-af02-4ec2-816c-4ca577cdb9f9","html_url":"https://github.com/kevin1024/pytest-httpbin","commit_stats":{"total_commits":128,"total_committers":12,"mean_commits":"10.666666666666666","dds":0.3671875,"last_synced_commit":"7b0f902822aa1dc698188ac1ceecc7c5207332e4"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin1024%2Fpytest-httpbin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin1024%2Fpytest-httpbin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin1024%2Fpytest-httpbin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin1024%2Fpytest-httpbin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevin1024","download_url":"https://codeload.github.com/kevin1024/pytest-httpbin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254364264,"owners_count":22058877,"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":[],"created_at":"2024-08-01T10:01:02.549Z","updated_at":"2025-05-15T15:01:48.596Z","avatar_url":"https://github.com/kevin1024.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# pytest-httpbin\n\n[![Build Status](https://github.com/kevin1024/pytest-httpbin/actions/workflows/main.yaml/badge.svg)](https://github.com/kevin1024/pytest-httpbin/actions/workflows/main.yaml)\n\n[httpbin](https://httpbin.org/) is an amazing web service for testing HTTP libraries. It\nhas several great endpoints that can test pretty much everything you need in a HTTP\nlibrary. The only problem is: maybe you don't want to wait for your tests to travel\nacross the Internet and back to make assertions against a remote web service (speed),\nand maybe you want to work offline (convenience).\n\nEnter **pytest-httpbin**. Pytest-httpbin creates a\n[pytest fixture](https://pytest.org/latest/fixture.html) that is dependency-injected\ninto your tests. It automatically starts up a HTTP server in a separate thread running\nhttpbin and provides your test with the URL in the fixture. Check out this example:\n\n```python\ndef test_that_my_library_works_kinda_ok(httpbin):\n    assert requests.get(httpbin.url + '/get').status_code == 200\n```\n\nThis replaces a test that might have looked like this before:\n\n```python\ndef test_that_my_library_works_kinda_ok():\n    assert requests.get('http://httpbin.org/get').status_code == 200\n```\n\nIf you're making a lot of requests to httpbin, it can radically speed up your tests.\n\n![demo](http://i.imgur.com/heNOQLP.gif)\n\n# HTTPS support\n\npytest-httpbin also supports HTTPS:\n\n```python\ndef test_that_my_library_works_kinda_ok(httpbin_secure):\n    assert requests.get(httpbin_secure.url + '/get/').status_code == 200\n```\n\nIt's actually starting 2 web servers in separate threads in the background: one HTTP and\none HTTPS. The servers are started on a random port (see below for fixed port support),\non the loopback interface on your machine. Pytest-httpbin includes a self-signed\ncertificate. If your library verifies certificates against a CA (and it should), you'll\nhave to add the CA from pytest-httpbin. The path to the pytest-httpbin CA bundle can by\nfound like this `python -m pytest_httpbin.certs`.\n\nFor example in requests, you can set the `REQUESTS_CA_BUNDLE` python path. You can run\nyour tests like this:\n\n```bash\nREQUESTS_CA_BUNDLE=`python -m pytest_httpbin.certs` py.test tests/\n```\n\n# API of the injected object\n\nThe injected object has the following attributes:\n\n- url\n- port\n- host\n\nand the following methods:\n\n- join(string): Returns the results of calling `urlparse.urljoin` with the url from the\n  injected server automatically applied as the first argument. You supply the second\n  argument\n\nAlso, I defined `__add__` on the object to append to `httpbin.url`. This means you can\ndo stuff like `httpbin + '/get'` instead of `httpbin.url + '/get'`.\n\n## Testing both HTTP and HTTPS endpoints with one test\n\nIf you ever find yourself needing to test both the http and https version of and\nendpoint, you can use the `httpbin_both` funcarg like this:\n\n```python\ndef test_that_my_library_works_kinda_ok(httpbin_both):\n    assert requests.get(httpbin_both.url + '/get/').status_code == 200\n```\n\nThrough the magic of pytest parametrization, this function will actually execute twice:\nonce with an http url and once with an https url.\n\n## Using pytest-httpbin with unittest-style test cases\n\nI have provided 2 additional fixtures to make testing with class-based tests easier. I\nhave also provided a couple decorators that provide some syntactic sugar around the\npytest method of adding the fixtures to class-based tests. Just add the\n`use_class_based_httpbin` and/or `use_class_based_httpbin_secure` class decorators to\nyour class, and then you can access httpbin using self.httpbin and self.httpbin_secure.\n\n```python\nimport pytest_httpbin\n\n@pytest_httpbin.use_class_based_httpbin\n@pytest_httpbin.use_class_based_httpbin_secure\nclass TestClassBassedTests(unittest.TestCase):\n    def test_http(self):\n        assert requests.get(self.httpbin.url + '/get').response\n\n    def test_http_secure(self):\n        assert requests.get(self.httpbin_secure.url + '/get').response\n```\n\n## Running the server on fixed port\n\nSometimes a randomized port can be a problem. Worry not, you can fix the port number to\na desired value with the `HTTPBIN_HTTP_PORT` and `HTTPBIN_HTTPS_PORT` environment\nvariables. If those are defined during pytest plugins are loaded, `httbin` and\n`httpbin_secure` fixtures will run on given ports. You can run your tests like this:\n\n```bash\nHTTPBIN_HTTP_PORT=8080 HTTPBIN_HTTPS_PORT=8443 py.test tests/\n```\n\n## Installation\n\n[![PyPI Version](https://img.shields.io/pypi/v/pytest-httpbin.svg)](https://pypi.org/project/pytest-httpbin/)\n[![Supported Versions](https://img.shields.io/pypi/pyversions/pytest-httpbin.svg)](https://pypi.org/project/pytest-httpbin/)\n\nTo install from [PyPI](https://pypi.org/project/pytest-httpbin/), all you need to do is\nthis:\n\n```bash\npip install pytest-httpbin\n```\n\nand your tests executed by pytest all will have access to the `httpbin` and\n`httpbin_secure` funcargs. Cool right?\n\n## Support and dependencies\n\npytest-httpbin supports Python 3.8+, and pypy. It will automatically\ninstall httpbin and flask when you install it from PyPI.\n\n[httpbin](https://github.com/postmanlabs/httpbin) itself does not support python 2.6 as\nof version 0.6.0, when the Flask-common dependency was added. If you need python 2.6\nsupport pin the httpbin version to 0.5.0\n\n## Running the pytest-httpbin test suite\n\nIf you want to run pytest-httpbin's test suite, you'll need to install requests and\npytest, and then use the ./runtests.sh script.\n\n```bash\npip install pytest\n./runtests.sh\n```\n\nAlso, you can use tox to run the tests on all supported python versions:\n\n```bash\npip install tox\ntox\n```\n\n## Changelog\n\n- 2.1.0\n  - Drop support for Python 3.7 (#85)\n  - Test against PyPy 3.10 (#77)\n  - Add support for CPython 3.13 by regenerating the bundled certificates (#90)\n  - Fix an issue where secure POST requests would fail with a connection reset\n    by peer (#90)\n  - Include a LICENCE\n- 2.0.0\n  - Drop support for Python 2.6, 2.7, 3.4, 3.5 and 3.6 (#68)\n  - Add support for Python 3.7, 3.8, 3.9 and 3.10 (#68)\n  - Avoid deprecation warnings and resource warnings (#71)\n  - Add support for Python 3.11 and 3.12, drop dependency on six (#76)\n- 1.0.2\n  - Switch from travis to github actions\n  - This will be the last release to support Python 2.6, 2.7 or 3.6\n- 1.0.1\n  - httpbin_secure: fix redirect Location to have \"https://\" scheme (#62) - thanks\n    @immerrr\n  - Include regression tests in pypi tarball (#56) - thanks @kmosiejczuk\n- 1.0.0\n  - Update included self-signed cert to include IP address in SAN (See #52). Full\n    version bump because this could be a breaking change for those depending on the\n    certificate missing the IP address in the SAN (as it seems the requests test suite\n    does)\n  - Only use @pytest.fixture decorator once (thanks @hroncok)\n  - Fix a few README typos (thanks @hemberger)\n- 0.3.0\n  - Allow to run httpbin on fixed port using environment variables (thanks @hroncok)\n  - Allow server to be thread.join()ed (thanks @graingert)\n  - Add support for Python 3.6 (thanks @graingert)\n- 0.2.3:\n  - Another attempt to fix #32 (Rare bug, only happens on Travis)\n- 0.2.2:\n  - Fix bug with python3\n- 0.2.1:\n  - Attempt to fix strange, impossible-to-reproduce bug with broken SSL certs that only\n    happens on Travis (#32) [Bad release, breaks py3]\n- 0.2.0:\n  - Remove threaded HTTP server. I built it for Requests, but they deleted their\n    threaded test since it didn't really work very well. The threaded server seems to\n    cause some strange problems with HTTP chunking, so I'll just remove it since nobody\n    is using it (I hope)\n- 0.1.1:\n  - Fix weird hang with SSL on pypy (again)\n- 0.1.0:\n  - Update server to use multithreaded werkzeug server\n- 0.0.7:\n  - Update the certificates (they expired)\n- 0.0.6:\n  - Fix an issue where pypy was hanging when a request was made with an invalid\n    certificate\n- 0.0.5:\n  - Fix broken version parsing in 0.0.4\n- 0.0.4:\n  - **Bad release: Broken version parsing**\n  - Fix `BadStatusLine` error that occurs when sending multiple requests in a single\n    session (PR #16). Thanks @msabramo!\n  - Fix #9 (\"Can't be installed at the same time than pytest?\") (PR #14). Thanks\n    @msabramo!\n  - Add `httpbin_ca_bundle` pytest fixture. With this fixture there is no need to\n    specify the bundle on every request, as it will automatically set\n    `REQUESTS_CA_BUNDLE` if using [requests](https://docs.python-requests.org/). And you\n    don't have to care about where it is located (PR #8). Thanks @t-8ch!\n- 0.0.3: Add a couple test fixtures to make testing old class-based test suites easier\n- 0.0.2: Fixed a couple bugs with the wsgiref server to bring behavior in line with\n  httpbin.org, thanks @jakubroztocil for the bug reports\n- 0.0.1: Initial release\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014-2019 Kevin McCarthy\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this\nsoftware and associated documentation files (the \"Software\"), to deal in the Software\nwithout restriction, including without limitation the rights to use, copy, modify,\nmerge, publish, distribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or\nsubstantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\nINCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\nPURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT\nOR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevin1024%2Fpytest-httpbin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevin1024%2Fpytest-httpbin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevin1024%2Fpytest-httpbin/lists"}