Metadata-Version: 2.1
Name: mockish
Version: 0.1.0
Summary: A thin layer of sugar atop Python's mock.
Home-page: https://www.github.com/fresh2dev/mockish
Author: Donald Mellenbruch
Author-email: hello@Fresh2.dev
Project-URL: Homepage, https://www.Fresh2.dev/code/r/mockish/i
Project-URL: Repository, https://www.github.com/fresh2dev/mockish
Project-URL: Funding, https://www.Fresh2.dev/funding
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests (==2.*)
Requires-Dist: httpx (==0.*)
Requires-Dist: pydantic (<2,>=1.10.3)
Requires-Dist: typing-extensions ; python_version < "3.10"
Provides-Extra: build
Requires-Dist: setuptools (>=62.3.0) ; extra == 'build'
Requires-Dist: build (==0.*) ; extra == 'build'
Requires-Dist: wheel (==0.*) ; extra == 'build'
Requires-Dist: twine (==4.*) ; extra == 'build'
Provides-Extra: dev
Requires-Dist: python-lsp-server[rope] (==1.*) ; extra == 'dev'
Requires-Dist: pylint (==2.*) ; extra == 'dev'
Requires-Dist: pylint-pytest (==1.*) ; extra == 'dev'
Requires-Dist: mypy[reports] (==0.*) ; extra == 'dev'
Requires-Dist: ruff (==0.*) ; extra == 'dev'
Requires-Dist: black (==23.*) ; extra == 'dev'
Requires-Dist: isort (==5.*) ; extra == 'dev'
Requires-Dist: ipython ; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs (==1.*) ; extra == 'docs'
Requires-Dist: mkdocs-material (==9.*) ; extra == 'docs'
Requires-Dist: mkdocstrings[python] (==0.20.*) ; extra == 'docs'
Requires-Dist: mkdocs-autorefs (==0.*) ; extra == 'docs'
Requires-Dist: mkdocs-include-dir-to-nav (==1.*) ; extra == 'docs'
Provides-Extra: tests
Requires-Dist: pytest (==7.*) ; extra == 'tests'
Requires-Dist: pytest-cov (==4.*) ; extra == 'tests'
Requires-Dist: pytest-html (==3.*) ; extra == 'tests'
Requires-Dist: pytest-sugar (==0.*) ; extra == 'tests'
Requires-Dist: pytest-custom-exit-code (==0.3.*) ; extra == 'tests'
Requires-Dist: pylint (==2.*) ; extra == 'tests'
Requires-Dist: pylint-pytest (==1.*) ; extra == 'tests'
Requires-Dist: packaging (==23.*) ; extra == 'tests'

# mockish

> A thin layer of sugar atop Python's mock.

| Links         |                                                   |
|---------------|---------------------------------------------------|
| Code Repo     | https://www.github.com/fresh2dev/mockish          |
| Mirror Repo   | https://www.Fresh2.dev/code/r/mockish             |
| Documentation | https://www.Fresh2.dev/code/r/mockish/i           |
| Changelog     | https://www.Fresh2.dev/code/r/mockish/i/changelog |
| License       | https://www.Fresh2.dev/code/r/mockish/i/license   |
| Funding       | https://www.Fresh2.dev/funding                    |

[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/fresh2dev/mockish?color=blue&style=for-the-badge)](https://www.github.com/fresh2dev/mockish/releases)
[![GitHub Release Date](https://img.shields.io/github/release-date/fresh2dev/mockish?color=blue&style=for-the-badge)](https://www.github.com/fresh2dev/mockish/releases)
[![License](https://img.shields.io/github/license/fresh2dev/mockish?color=blue&style=for-the-badge)](https://www.Fresh2.dev/code/r/mockish/i/license)
[![GitHub issues](https://img.shields.io/github/issues-raw/fresh2dev/mockish?color=blue&style=for-the-badge)](https://www.github.com/fresh2dev/mockish/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/fresh2dev/mockish?color=blue&style=for-the-badge)](https://www.github.com/fresh2dev/mockish/pulls)
[![GitHub Repo stars](https://img.shields.io/github/stars/fresh2dev/mockish?color=blue&style=for-the-badge)](https://star-history.com/#fresh2dev/mockish&Date)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/mockish?color=blue&style=for-the-badge)](https://pypi.org/project/mockish)
[![Docs Website](https://img.shields.io/website?down_message=unavailable&label=docs&style=for-the-badge&up_color=blue&up_message=available&url=https://www.Fresh2.dev/code/r/mockish/i)](https://www.Fresh2.dev/code/r/mockish/i)
[![Coverage Website](https://img.shields.io/website?down_message=unavailable&label=coverage&style=for-the-badge&up_color=blue&up_message=available&url=https://www.Fresh2.dev/code/r/mockish/i/tests/coverage)](https://www.Fresh2.dev/code/r/mockish/i/tests/coverage)
[![Funding](https://img.shields.io/badge/funding-%24%24%24-blue?style=for-the-badge)](https://www.Fresh2.dev/funding)

*Brought to you by...*

[![](https://img.fresh2.dev/fresh2dev.svg)](https://www.fresh2.dev)

---

## 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](https://pypi.org/project/mockish/){:target="_blank"}:

```py
pip install mockish
```

## Use

Complete example of mocking a HTTP response:

```py
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:

- [mockish.Mock](https://www.Fresh2.dev/code/r/mockish/i/reference/01)
- [mockish.httpx.Response](https://www.Fresh2.dev/code/r/mockish/i/reference/02)
- [mockish.requests.Response](https://www.Fresh2.dev/code/r/mockish/i/reference/03)

## Support

If this project delivers value to you, please [provide feedback](https://github.com/fresh2dev/mockish/issues), code contributions, and/or [funding](https://www.Fresh2.dev/funding).
