flexmock


Nameflexmock JSON
Version 0.12.1 PyPI version JSON
download
home_pagehttps://github.com/flexmock/flexmock
Summaryflexmock is a testing library for Python that makes it easy to create mocks, stubs and fakes.
upload_time2024-03-29 14:50:24
maintainerAdarsh Krishnan
docs_urlNone
authorSlavek Kabrda
requires_python<4.0.0,>=3.8.0
licenseBSD-2-Clause
keywords mock testing test unittest pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img alt="banner" src="https://user-images.githubusercontent.com/25169984/138661460-969caf9e-8e88-4609-87c4-1a0ab9624ee4.png">
</p>

<p align="center"><strong>flexmock</strong> <em>- Mock, stub, and spy library for Python.</em></p>

<p align="center">
<a href="https://pypi.org/project/flexmock/">
  <img src="https://img.shields.io/pypi/v/flexmock" alt="pypi">
</a>
<a href="https://github.com/flexmock/flexmock/actions/workflows/ci.yml">
  <img src="https://github.com/flexmock/flexmock/actions/workflows/ci.yml/badge.svg" alt="ci">
</a>
<a href="https://flexmock.readthedocs.io/">
  <img src="https://img.shields.io/readthedocs/flexmock" alt="documentation">
</a>
<a href="https://codecov.io/gh/flexmock/flexmock">
  <img src="https://codecov.io/gh/flexmock/flexmock/branch/master/graph/badge.svg?token=wRgtiGxhiL" alt="codecov">
</a>
<a href="./LICENSE">
  <img src="https://img.shields.io/pypi/l/flexmock" alt="license">
</a>
</p>

---

Flexmock is a testing library for Python that makes it easy to create mocks, stubs, and fakes.

## Features

- **Mock**: Easily create mock objects and make assertions about which methods or attributes were used and arguments they were called with.
- **Spy**: Proxy calls to object's original methods or attributes and make assertions based on return values or call count.
- **Fake**: Generate a fake objects to be used in your tests with ease.
- **Stub**: Create stub objects which replace parts of existing objects and classes with just one call.
- **No external dependencies**: Flexmock is lightweight and only uses Python standard library. There are no external dependencies.
- **Simple and intuitive**: Declarations are structured to read more like English sentences than API calls, so they are easy to learn and use.
- **Fully type annotated**: External API is fully type annotated so it works great with static analysis tools and editor auto-completion.
- **Integrations with test runners**: Integrates seamlessly with all major test runners like unittest, doctest, and pytest.
- **Python 3.6+ and PyPy3**: Extensively tested to work with latest Python versions.

## Installation

Install with pip:

```
pip install flexmock
```

## Examples

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:

```python
from flexmock import flexmock
```

### Mocks

Assertions take many flavors and flexmock has many different facilities to generate them:

```python
# 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()
```

### Spies

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`:

```python
# 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.

## Documentation

User guide, examples, and a full API reference is available at: https://flexmock.readthedocs.io

## Contributing

Contributions are absolutely welcome and encouraged! See [CONTRIBUTING.md](https://github.com/flexmock/flexmock/blob/master/CONTRIBUTING.md) to get started.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/flexmock/flexmock",
    "name": "flexmock",
    "maintainer": "Adarsh Krishnan",
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.8.0",
    "maintainer_email": "adarshk7@gmail.com",
    "keywords": "mock, testing, test, unittest, pytest",
    "author": "Slavek Kabrda",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/f0/6b/b53fc99d6fa6f2e598644f34cf879c554e5e3254c6a216a4e0bb10f2b34b/flexmock-0.12.1.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img alt=\"banner\" src=\"https://user-images.githubusercontent.com/25169984/138661460-969caf9e-8e88-4609-87c4-1a0ab9624ee4.png\">\n</p>\n\n<p align=\"center\"><strong>flexmock</strong> <em>- Mock, stub, and spy library for Python.</em></p>\n\n<p align=\"center\">\n<a href=\"https://pypi.org/project/flexmock/\">\n  <img src=\"https://img.shields.io/pypi/v/flexmock\" alt=\"pypi\">\n</a>\n<a href=\"https://github.com/flexmock/flexmock/actions/workflows/ci.yml\">\n  <img src=\"https://github.com/flexmock/flexmock/actions/workflows/ci.yml/badge.svg\" alt=\"ci\">\n</a>\n<a href=\"https://flexmock.readthedocs.io/\">\n  <img src=\"https://img.shields.io/readthedocs/flexmock\" alt=\"documentation\">\n</a>\n<a href=\"https://codecov.io/gh/flexmock/flexmock\">\n  <img src=\"https://codecov.io/gh/flexmock/flexmock/branch/master/graph/badge.svg?token=wRgtiGxhiL\" alt=\"codecov\">\n</a>\n<a href=\"./LICENSE\">\n  <img src=\"https://img.shields.io/pypi/l/flexmock\" alt=\"license\">\n</a>\n</p>\n\n---\n\nFlexmock is a testing library for Python that makes it easy to create mocks, stubs, and fakes.\n\n## Features\n\n- **Mock**: Easily create mock objects and make assertions about which methods or attributes were used and arguments they were called with.\n- **Spy**: Proxy calls to object's original methods or attributes and make assertions based on return values or call count.\n- **Fake**: Generate a fake objects to be used in your tests with ease.\n- **Stub**: Create stub objects which replace parts of existing objects and classes with just one call.\n- **No external dependencies**: Flexmock is lightweight and only uses Python standard library. There are no external dependencies.\n- **Simple and intuitive**: Declarations are structured to read more like English sentences than API calls, so they are easy to learn and use.\n- **Fully type annotated**: External API is fully type annotated so it works great with static analysis tools and editor auto-completion.\n- **Integrations with test runners**: Integrates seamlessly with all major test runners like unittest, doctest, and pytest.\n- **Python 3.6+ and PyPy3**: Extensively tested to work with latest Python versions.\n\n## Installation\n\nInstall with pip:\n\n```\npip install flexmock\n```\n\n## Examples\n\nFlexmock 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:\n\n```python\nfrom flexmock import flexmock\n```\n\n### Mocks\n\nAssertions take many flavors and flexmock has many different facilities to generate them:\n\n```python\n# Simplest is ensuring that a certain method is called\nflexmock(Train).should_receive(\"get_tickets\").once()\n\n# Of course, it is also possible to provide a default return value\nflexmock(Train).should_receive(\"get_destination\").and_return(\"Paris\").once()\n\n# Or check that a method is called with specific arguments\nflexmock(Train).should_receive(\"set_destination\").with_args(\"Seoul\").at_least().twice()\n```\n\n### Spies\n\nInstead 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`:\n\n```python\n# Verify that a method is called at most three times\nflexmock(Train).should_call(\"get_tickets\").at_most().times(3)\n\n# Make sure that a method is never called with specific arguments\nflexmock(Train).should_call(\"set_destination\").with_args(\"Helsinki\").never()\n\n# More complex example with features like argument type and exception matching\nflexmock(Train).should_call(\"crash\").with_args(str, int).and_raise(AttributeError).once()\n```\n\nSee more examples in the documentation.\n\n## Documentation\n\nUser guide, examples, and a full API reference is available at: https://flexmock.readthedocs.io\n\n## Contributing\n\nContributions are absolutely welcome and encouraged! See [CONTRIBUTING.md](https://github.com/flexmock/flexmock/blob/master/CONTRIBUTING.md) to get started.\n",
    "bugtrack_url": null,
    "license": "BSD-2-Clause",
    "summary": "flexmock is a testing library for Python that makes it easy to create mocks, stubs and fakes.",
    "version": "0.12.1",
    "project_urls": {
        "Changes": "https://flexmock.readthedocs.io/en/latest/changelog/",
        "Documentation": "https://flexmock.readthedocs.io",
        "Homepage": "https://github.com/flexmock/flexmock",
        "Issue Tracker": "https://github.com/flexmock/flexmock/issues",
        "Repository": "https://github.com/flexmock/flexmock",
        "Source Code": "https://github.com/flexmock/flexmock"
    },
    "split_keywords": [
        "mock",
        " testing",
        " test",
        " unittest",
        " pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "358948b078f4306fb541af4c877e2ca82b0359c12576fac26459d5044a7d44a0",
                "md5": "180f0419243190ae7fc124e044ac0e1d",
                "sha256": "53a1f0cd3e0a701a7cce6863974cce767f0986ca791a9fcb80081a2640cd1ab5"
            },
            "downloads": -1,
            "filename": "flexmock-0.12.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "180f0419243190ae7fc124e044ac0e1d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.8.0",
            "size": 20566,
            "upload_time": "2024-03-29T14:50:21",
            "upload_time_iso_8601": "2024-03-29T14:50:21.716913Z",
            "url": "https://files.pythonhosted.org/packages/35/89/48b078f4306fb541af4c877e2ca82b0359c12576fac26459d5044a7d44a0/flexmock-0.12.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f06bb53fc99d6fa6f2e598644f34cf879c554e5e3254c6a216a4e0bb10f2b34b",
                "md5": "22d081c53376411777df6ae53a7671de",
                "sha256": "20b690afa4ff8c6f31548d896d6d41cca1fc9050a4cf628b965ea434ec548ee3"
            },
            "downloads": -1,
            "filename": "flexmock-0.12.1.tar.gz",
            "has_sig": false,
            "md5_digest": "22d081c53376411777df6ae53a7671de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.8.0",
            "size": 52765,
            "upload_time": "2024-03-29T14:50:24",
            "upload_time_iso_8601": "2024-03-29T14:50:24.073152Z",
            "url": "https://files.pythonhosted.org/packages/f0/6b/b53fc99d6fa6f2e598644f34cf879c554e5e3254c6a216a4e0bb10f2b34b/flexmock-0.12.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-29 14:50:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "flexmock",
    "github_project": "flexmock",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flexmock"
}
        
Elapsed time: 0.24809s