pytest-responsemock
https://github.com/idlesign/pytest-responsemock
Description
Simplified requests calls mocking for pytest
Provides response_mock fixture, exposing simple context manager.
Any request under that manager will be intercepted and mocked according to one or more rules passed to the manager. If actual request won’t fall under any of given rules then an exception is raised (by default).
Rules are simple strings, of the pattern: HTTP_METHOD URL -> STATUS_CODE :BODY.
Requirements
Python 3.7+
Usage
When this package is installed response_mock is available for pytest test functions.
def for_test():
return requests.get('http://some.domain')
def test_me(response_mock):
# Pass response rule as a string,
# or many rules (to mock consequent requests) as a list of strings/bytes.
# Use optional `bypass` argument to disable mock conditionally.
with response_mock('GET http://some.domain -> 200 :Nice', bypass=False):
result = for_test()
assert result.ok
assert result.content == b'Nice'
# mock consequent requests
with response_mock([
'GET http://some.domain -> 200 :Nice',
'GET http://other.domain -> 200 :Sweet',
]):
for_test()
requests.get('http://other.domain')
Use with pytest-datafixtures:
def test_me(response_mock, datafix_read):
with response_mock(f"GET http://some.domain -> 200 :{datafix_read('myresponse.html')}"):
...
Describe response header fields using multiline strings:
with response_mock(
'''
GET http://some.domain
Allow: GET, HEAD
Content-Language: ru
-> 200 :OK
'''
):
...
Test json response:
response = json.dumps({'key': 'value', 'another': 'yes'})
with response_mock(f'POST http://some.domain -> 400 :{response}'):
...
To test binary response pass rule as bytes:
with response_mock(b'GET http://some.domain -> 200 :' + my_bytes):
...
Access underlying RequestsMock (from responses package) as mock:
with response_mock('HEAD http://some.domain -> 200 :Nope') as mock:
mock.add_passthru('http://other.domain')
Metadata
Release files for pytest-responsemock 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest-responsemock-1.1.1.tar.gz | 6.3 kB | Without provenance | Details for pytest-responsemock-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_responsemock-1.1.1-py2-none-any.whl | Python 2 | none | any | Details for pytest_responsemock-1.1.1-py2-none-any.whl |
Total release size: 12.8 kB
Release files / pytest-responsemock-1.1.1.tar.gz
| Download URL | pytest-responsemock-1.1.1.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71abcebaf61f8930bd92bd643bfc9bc2891299e4e819e21fec18c8434d5dc9af
|
|
BLAKE2b-256 checksum How to use checksums |
a210e9ad385e041aa755f3ec16b91b72a7485bc3f900b087408ae176a7022241
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/2.7
|
Release files / pytest_responsemock-1.1.1-py2-none-any.whl
| Download URL | pytest_responsemock-1.1.1-py2-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
bb2583f0cf64e8b47183464d43fe30656ddb7318f64ff2fdf935067827c461c0
|
|
BLAKE2b-256 checksum How to use checksums |
86872f1653c6730f941b978d1e816072815685ad09de7b7f7f8966b0b9ab44fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/2.7
|
Security for pytest-responsemock 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.