Skip to content

Commit

Permalink
Small updates to readme
Browse files Browse the repository at this point in the history
- Fix typos and grammar
- Add similar projects section
  • Loading branch information
ollipa committed Feb 7, 2022
1 parent 1c68019 commit a7656dc
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
Mocking library for Python and Pytest.

Chainmock is a wrapper for Python unittest unit testing library. It provides an
alternative syntax to create mocks and assertions and adds some additional
features to make testing fast and straightforward. The syntax works especially
well with pytest fixtures and it makes the tests easy to read.
alternative syntax to create mocks and assertions with some additional features
to make testing faster and more straightforward. The syntax works especially
well with pytest fixtures.

**Documentation**: https://chainmock.readthedocs.io/

Expand All @@ -41,21 +41,21 @@ supports and adds some convenient extra functionality.

- **Mocking**: Create _mocks_ and assert call counts and arguments or replace
return values.
- **Spying**: _Spying_ proxies the calls to the original function or method and
you can assert call counts and arguments.
- **Spying**: _Spying_ proxies the calls to the original function or method.
With spying you can assert call counts and arguments without mocking.
- **Stubs**: Easily create _stub_ objects that can be used in tests as fake data
or to replace real objects.
- **Async support**: Chainmock supports mocking and spying _async_ functions and
methods. Most of the time it also automatically recognizes when async mocking
methods. Most of the time it also recognizes automatically when async mocking
should be used so it is not any harder than mocking sync code.
- **Fully type annotated**: The whole codebase is fully type annotated so
Chainmock works well with editor auto completion and static analysis tools.
Chainmock works well with static analysis tools and editor autocomplete.
- Works with **Python 3.8+ and PyPy3**.

## Examples

The entrypoint to Chainmock is the `mocker` function. Import the `mocker`
as follows:
function as follows:

```python
from chainmock import mocker
Expand All @@ -79,15 +79,16 @@ mocker(Teapot).mock("add_tea").all_calls_with("green").call_count_at_most(2)

### Spying

Spying is easy with Chainmock. You just need to call `spy` instead of `mock`.
After spying a method, the method works just like before, but you can assert
call count and check if it was called with specific arguments.
Spying is not any harder than mocking. You just need to call the `spy` method
instead of the `mock` method. After spying a callable, it works just like before
spying and you can start making assertions on it.

```python
# Assert that a certain method has been called at least once
mocker(Teapot).spy("add_tea").called()

# Check that a method has been called at least once with the given arguments
# Check that a method has been called at most twice and has
# at least one call with the given argument
mocker(Teapot).spy("add_tea").any_call_with("green").call_count_at_most(2)
```

Expand All @@ -107,6 +108,20 @@ assert stub.my_property == 10

For more details and examples, see the documentation.

## Similar projects

If chainmock is not what you need, check out also these cool projects:

- [flexmock](https://github.com/flexmock/flexmock): Chainmock's API is heavily
inspired by flexmock. Flexmock doesn't use standard library unittest and it
has fully custom mocking implementation. Compared to flexmock, chainmock has
more familiar API if you have been using standard library unittest. Chainmock
also supports async mocking and partial argument matching.
- [pytest-mock](https://github.com/pytest-dev/pytest-mock/): Similar to
chainmock, pytest-mock is a wrapper for standard library unittest. However,
pytest-mock doesn't provide any extra functionality and it exposes unittest
mocks directly to the user.

## Contributing

Do you like this project and want to help? If you need ideas, check out the open issues and feel free to open a new pull request. Bug reports and feature requests are also very welcome.

0 comments on commit a7656dc

Please sign in to comment.