This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

auto_mock is a module for mocking during unit testing. It automatically replaces all variables and functions external to the unit with default values to help developers exclude external state in their unit tests.

Installation

pip install python-auto-mock

Usage

In the example we will be making use of myclass.py

myclass.py

X = 1
Y = 2
Z = 3

class MyClass():
    def addition_with_globals(self):
        print(X)
        print(Y)
        print(X + Y)
        return X + Y

To test this class we will write a test script.

import auto_mock

def test_my_class_addition():
    stubs = {
        'X' : 36,
        'Y' : 35,
    }

    with auto_mock.full_mock('myclass', 'MyClass.addition_with_globals', stubs) as addition_with_globals:
        if addition_with_globals() != 71:
            print("Addition is broken")

def main():
    test_my_class_addition()

main()

Done correctly this should print out

36
35
71

full_mock takes 3 non optional arguments.

  1. The module name where the code is located.
  2. The specific function or method that is being tested.
  3. The dictionary of stubs/mocks that you would like to override the values with.

The stubs variable contains the names of the variables that are being mocked. In this example we have X, Y, and Z as global variables. We only use X and Y in this example, so they are the only variables that are in the stubs dictionary.

full_mock returns the function or method that you are trying to test with the external variables mocked. If the variable is not within the stubs then it is mocked with a default object. Inside the with block you can test that the function does what it is supposed to do.

Release History

Release History

0.1.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
python_auto_mock-0.1.1-py2.py3-none-any.whl (5.4 kB) Copy SHA256 Checksum SHA256 3.5 Wheel Feb 26, 2016
python-auto-mock-0.1.1.tar.gz (4.3 kB) Copy SHA256 Checksum SHA256 Source Feb 26, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting