Skip to content

Testing

lachmanfrantisek edited this page Feb 20, 2019 · 6 revisions

Mocking

Flexmock

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"])
    ),
)

TOX

Clone this wiki locally