Skip to content

Testing

lachmanfrantisek edited this page Feb 9, 2019 · 6 revisions

Mocking

Flexmock

  • Library for very easy mocking of Python objects.
  • 💻 github.com/bkabrda/flexmock, 📜 documentation
  • PyPI - Python Version, PyPI, 📦 fedora packages
    • Allows specifying multiple attributes and methods together. Example of git.Repo mock:
    flexmock(
        active_branch="branch",
        working_dir="example/path",
        remote=lambda: flexmock(urls=["http://example/url"]),
    )
    • Easy checking of calls, replacing of the method implementation:
    flexmock()
    .should_receive("get_project")
    .with_args(repo="repo", namespace="namespace")
    .replace_with(lambda repo, namespace: flexmock())
    .mock()
    • Overwritting existing objects:
    flexmock(git.Repo)
    .should_receive("remote")
    .replace_with(lambda: flexmock(urls=["http://example/url"]))
    .mock()
  • ➖ :
    • Mocking of the imports.
Clone this wiki locally