Skip to main content

mockish

A thin layer of sugar atop Python's mock.

Links
Code Repo https://www.github.com/fresh2dev/mockish
Mirror Repo https://www.f2dv.com/code/r/mockish
Documentation https://www.f2dv.com/code/r/mockish/i
Changelog https://www.f2dv.com/code/r/mockish/i/changelog
License https://www.f2dv.com/code/r/mockish/i/license
Funding https://www.f2dv.com/fund

GitHub release (latest SemVer) GitHub Release Date License GitHub issues GitHub pull requests GitHub Repo stars PyPI - Downloads Docker Pulls Docs Website Coverage Website Funding


Overview

mockish is a small tool I built to make life easier when writing tests in Python.

It provides:

  1. Explicit alternatives to the nuanced mock.Mock(side_effect=...) argument, including:

    • mockish.Mock(return_value=...)
    • mockish.Mock(return_call=...)
    • mockish.Mock(return_once=...)
    • mockish.Mock(return_each=...)
    • mockish.Mock(return_exception=...)
  2. Methods for creating HTTP responses -- both requests.Response and httpx.Response objects -- that can be returned by the Mock, including:

    • mockish.httpx.Response.from_dict(...)
    • mockish.requests.Response.from_dict(...)

Install

From PyPi{:target="_blank"}:

pip install mockish

Use

Complete example of mocking a HTTP response:

from mockish import Mock, patch
from mockish.requests import Response
import requests

mock_resp = Response.from_dict({'hello': 'world'})

with patch.object(
    requests,
    'get',
    Mock(return_once=mock_resp)
):
    resp: requests.Response = requests.get('https://www.fresh2.dev')

    requests.get.assert_called_once()

print(resp)
> <Response [200]>

print(resp.json())
> {'hello': 'world'}

See the reference docs for more examples:

Support

If this project delivers value to you, please provide feedback, code contributions, and/or funding.

Metadata

Release files for mockish 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mockish 0.1.1
File Size Uploaded Provenance Actions
mockish-0.1.1.tar.gz 53.3 kB Without provenance Details for mockish-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mockish 0.1.1
File Interpreter ABI Platform Actions
mockish-0.1.1-py3-none-any.whl Python 3 none any Details for mockish-0.1.1-py3-none-any.whl

Total release size: 96.5 kB

Release files / mockish-0.1.1.tar.gz

Download URL mockish-0.1.1.tar.gz
Size 53.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5eb86d4b80b8a04726d30f0cd9f362601e8df5099d574426e0fd9cc8b36d6de1
BLAKE2b-256 checksum
How to use checksums
1f46cc45ff97d8e3c02fff3bf1293074fb1e32702d586f4f479305193e5244de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / mockish-0.1.1-py3-none-any.whl

Download URL mockish-0.1.1-py3-none-any.whl
Size 43.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0a52eeb409d058ce3a59fe523928b81e741b7c3482643eed044569d90de0e81
BLAKE2b-256 checksum
How to use checksums
be4284788b3735a23bcfb857bfa5fc2bf4beb77e9fc8b89d37ccb624df8fbd72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for mockish 0.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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page