Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
flexmock is a testing library for Python that makes it easy to create mocks, stubs and fakes.
flexmock - Mock, stub, and spy library for Python.
Flexmock is a testing library for Python that makes it easy to create mocks, stubs, and fakes.
Install with pip:
pip install flexmock
Flexmock features smooth integration with pretty much every popular test runner, so no special setup is necessary. Simply importing flexmock into your test module is sufficient to get started with any of the following examples:
from flexmock import flexmock
Assertions take many flavors and flexmock has many different facilities to generate them:
# Simplest is ensuring that a certain method is called
flexmock(Train).should_receive("get_tickets").once()
# Of course, it is also possible to provide a default return value
flexmock(Train).should_receive("get_destination").and_return("Paris").once()
# Or check that a method is called with specific arguments
flexmock(Train).should_receive("set_destination").with_args("Seoul").at_least().twice()
Instead of mocking, there are also times when you want to execute the actual method and simply find out how many times it was called. Flexmock uses should_call
to generate this sort of assertions instead of should_receive
:
# Verify that a method is called at most three times
flexmock(Train).should_call("get_tickets").at_most().times(3)
# Make sure that a method is never called with specific arguments
flexmock(Train).should_call("set_destination").with_args("Helsinki").never()
# More complex example with features like argument type and exception matching
flexmock(Train).should_call("crash").with_args(str, int).and_raise(AttributeError).once()
See more examples in the documentation.
User guide, examples, and a full API reference is available at: https://flexmock.readthedocs.io
Contributions are absolutely welcome and encouraged! See CONTRIBUTING.md to get started.
FAQs
flexmock is a testing library for Python that makes it easy to create mocks, stubs and fakes.
We found that flexmock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.