-
Notifications
You must be signed in to change notification settings - Fork 4
Testing
lachmanfrantisek edited this page Feb 20, 2019
·
6 revisions
- Library for very easy mocking of Python objects.
- 💻 github.com/bkabrda/flexmock, 📜 documentation
- , , 📦 fedora packages
- Allows specifying multiple attributes and methods together. Example of
git.Repo
mock:
mocked_object = flexmock(
active_branch="branch",
working_dir="example/path",
remote=lambda: flexmock(urls=["http://example/url"]),
)
- Easy checking of calls, replacing of the method implementation:
mocked_object = (
flexmock()
.should_receive("get_project")
.with_args(repo="repo", namespace="namespace")
.replace_with(lambda repo, namespace: flexmock())
.mock()
)
- Overwritting existing objects:
MockedRepo = (
flexmock(git.Repo)
.should_receive("remote")
.replace_with(lambda: flexmock(urls=["http://example/url"]))
.mock()
)
repo = MockedRepo()
- Mocking of the imports (objects/functions used somewhere in the code) -- same syntax, but you do not need to finalize with
.mock()
:
flexmock(
git,
Repo=flexmock(
active_branch="branch", remote=lambda: flexmock(urls=["git/url"])
),
)
- Test command line tool with support to check against multiple Python versions/interpreters.
- 💻 github.com/tox-dev/tox/, 📜 documentation
- , , 📦 fedora packages