# Mockstar -- Mocking Like a Rockstar!

Mockstar is a bunch of small enhances on top of Mock library that can give you a lot of mocking and unit-testing goods.

Note

Mockstar is still in development, but my team already uses it in our project heavily, so it should get stable API soon.

Author: Konstantine Rybnikov. Main repository on bitbucket: https://bitbucket.org/k_bx/mockstar.

## Unit-testing with MockStar

So, you want to implement and test your unit. Let's say it's a function :func:create_user that will look like this when it is done:

This unit consists of input-parameters:

• email
• full_name

and seven side-effects:

• User model
• not_md5_and_has_salt function
• count_score function
• choose_low_quality_avatar function
• choose_high_quality_avatar function
• discover_possible_friends function

So, to test this unit in isolation we would need to mock-out all side-effects, on every test put some return-values so that they will fit our if-else clauses, and finally, generate suitable input-parameters.

With Mock library, you would do something like this:

Problems I see:

• need to repeat mocked names as test parameters
• need to write autospec=True again and again
• need to write module prefix app.bl.user on every patch call
• need to patch on every test case
• need to add common return_values and assign to some variables (like user) that we'll use later in asserts
• side_effects take a lot of space in our testing code, I want to separate them

With mockstar your test would look something like this:

I hope you like mockstar's aspiration to fight copy-paste and useless typing.

## Installation

To install mockstar, just type:

pip install mockstar


## Indices and tables

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.