snapshottest


Namesnapshottest JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/syrusakbary/snapshottest
SummarySnapshot testing for pytest, unittest, Django, and Nose
upload_time2020-09-29 03:54:51
maintainer
docs_urlNone
authorSyrus Akbary
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # SnapshotTest [![travis][travis-image]][travis-url] [![pypi][pypi-image]][pypi-url]

[travis-image]: https://img.shields.io/travis/syrusakbary/snapshottest.svg?style=flat
[travis-url]: https://travis-ci.org/syrusakbary/snapshottest
[pypi-image]: https://img.shields.io/pypi/v/snapshottest.svg?style=flat
[pypi-url]: https://pypi.python.org/pypi/snapshottest


Snapshot testing is a way to test your APIs without writing actual test cases.

1. A snapshot is a single state of your API, saved in a file.
2. You have a set of snapshots for your API endpoints.
3. Once you add a new feature, you can generate *automatically* new snapshots for the updated API.

## Installation

    $ pip install snapshottest


## Usage with unittest/nose

```python
from snapshottest import TestCase

class APITestCase(TestCase):
    def test_api_me(self):
        """Testing the API for /me"""
        my_api_response = api.client.get('/me')
        self.assertMatchSnapshot(my_api_response)

        # Set custom snapshot name: `gpg_response`
        my_gpg_response = api.client.get('/me?gpg_key')
        self.assertMatchSnapshot(my_gpg_response, 'gpg_response')
```

If you want to update the snapshots automatically you can use the `nosetests --snapshot-update`.

Check the [Unittest example](https://github.com/syrusakbary/snapshottest/tree/master/examples/unittest).

## Usage with pytest

```python
def test_mything(snapshot):
    """Testing the API for /me"""
    my_api_response = api.client.get('/me')
    snapshot.assert_match(my_api_response)

    # Set custom snapshot name: `gpg_response`
    my_gpg_response = api.client.get('/me?gpg_key')
    snapshot.assert_match(my_gpg_response, 'gpg_response')
```

If you want to update the snapshots automatically you can use the `--snapshot-update` config.

Check the [Pytest example](https://github.com/syrusakbary/snapshottest/tree/master/examples/pytest).

## Usage with django
Add to your settings:
```python
TEST_RUNNER = 'snapshottest.django.TestRunner'
```
To create your snapshottest:
```python
from snapshottest.django import TestCase

class APITestCase(TestCase):
    def test_api_me(self):
        """Testing the API for /me"""
        my_api_response = api.client.get('/me')
        self.assertMatchSnapshot(my_api_response)
```
If you want to update the snapshots automatically you can use the `python manage.py test --snapshot-update`.
Check the [Django example](https://github.com/syrusakbary/snapshottest/tree/master/examples/django_project).

## Disabling terminal colors

Set the environment variable `ANSI_COLORS_DISABLED` (to any value), e.g. 

    ANSI_COLORS_DISABLED=1 pytest


# Contributing

After cloning this repo and configuring a virtualenv for snapshottest (optional, but highly recommended), ensure dependencies are installed by running:

```sh
make install
```

After developing, the full test suite can be evaluated by running:

```sh
make lint
# and
make test
```

# Notes

This package is heavily inspired in [jest snapshot testing](https://facebook.github.io/jest/docs/snapshot-testing.html).

# Reasons to use this package

> Most of this content is taken from the [Jest snapshot blogpost](https://facebook.github.io/jest/blog/2016/07/27/jest-14.html).

We want to make it as frictionless as possible to write good tests that are useful.
We observed that when engineers are provided with ready-to-use tools, they end up writing more tests, which in turn results in stable and healthy code bases.

However engineers frequently spend more time writing a test than the component itself. As a result many people stopped writing tests altogether which eventually led to instabilities.

A typical snapshot test case for a mobile app renders a UI component, takes a screenshot, then compares it to a reference image stored alongside the test. The test will fail if the two images do not match: either the change is unexpected, or the screenshot needs to be updated to the new version of the UI component.


## Snapshot Testing with SnapshotTest

A similar approach can be taken when it comes to testing your APIs.
Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your API response.


## License

[MIT License](https://github.com/syrusakbary/snapshottest/blob/master/LICENSE)

[![coveralls][coveralls-image]][coveralls-url]

[coveralls-image]: https://coveralls.io/repos/syrusakbary/snapshottest/badge.svg?branch=master&service=github
[coveralls-url]: https://coveralls.io/github/syrusakbary/snapshottest?branch=master



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/syrusakbary/snapshottest",
    "name": "snapshottest",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Syrus Akbary",
    "author_email": "me@syrusakbary.com",
    "download_url": "https://files.pythonhosted.org/packages/14/6a/6a6ff192326d79048f44c9348acad760070cce68f9fc9c9832c3efa7aca8/snapshottest-0.6.0.tar.gz",
    "platform": "",
    "description": "# SnapshotTest [![travis][travis-image]][travis-url] [![pypi][pypi-image]][pypi-url]\n\n[travis-image]: https://img.shields.io/travis/syrusakbary/snapshottest.svg?style=flat\n[travis-url]: https://travis-ci.org/syrusakbary/snapshottest\n[pypi-image]: https://img.shields.io/pypi/v/snapshottest.svg?style=flat\n[pypi-url]: https://pypi.python.org/pypi/snapshottest\n\n\nSnapshot testing is a way to test your APIs without writing actual test cases.\n\n1. A snapshot is a single state of your API, saved in a file.\n2. You have a set of snapshots for your API endpoints.\n3. Once you add a new feature, you can generate *automatically* new snapshots for the updated API.\n\n## Installation\n\n    $ pip install snapshottest\n\n\n## Usage with unittest/nose\n\n```python\nfrom snapshottest import TestCase\n\nclass APITestCase(TestCase):\n    def test_api_me(self):\n        \"\"\"Testing the API for /me\"\"\"\n        my_api_response = api.client.get('/me')\n        self.assertMatchSnapshot(my_api_response)\n\n        # Set custom snapshot name: `gpg_response`\n        my_gpg_response = api.client.get('/me?gpg_key')\n        self.assertMatchSnapshot(my_gpg_response, 'gpg_response')\n```\n\nIf you want to update the snapshots automatically you can use the `nosetests --snapshot-update`.\n\nCheck the [Unittest example](https://github.com/syrusakbary/snapshottest/tree/master/examples/unittest).\n\n## Usage with pytest\n\n```python\ndef test_mything(snapshot):\n    \"\"\"Testing the API for /me\"\"\"\n    my_api_response = api.client.get('/me')\n    snapshot.assert_match(my_api_response)\n\n    # Set custom snapshot name: `gpg_response`\n    my_gpg_response = api.client.get('/me?gpg_key')\n    snapshot.assert_match(my_gpg_response, 'gpg_response')\n```\n\nIf you want to update the snapshots automatically you can use the `--snapshot-update` config.\n\nCheck the [Pytest example](https://github.com/syrusakbary/snapshottest/tree/master/examples/pytest).\n\n## Usage with django\nAdd to your settings:\n```python\nTEST_RUNNER = 'snapshottest.django.TestRunner'\n```\nTo create your snapshottest:\n```python\nfrom snapshottest.django import TestCase\n\nclass APITestCase(TestCase):\n    def test_api_me(self):\n        \"\"\"Testing the API for /me\"\"\"\n        my_api_response = api.client.get('/me')\n        self.assertMatchSnapshot(my_api_response)\n```\nIf you want to update the snapshots automatically you can use the `python manage.py test --snapshot-update`.\nCheck the [Django example](https://github.com/syrusakbary/snapshottest/tree/master/examples/django_project).\n\n## Disabling terminal colors\n\nSet the environment variable `ANSI_COLORS_DISABLED` (to any value), e.g. \n\n    ANSI_COLORS_DISABLED=1 pytest\n\n\n# Contributing\n\nAfter cloning this repo and configuring a virtualenv for snapshottest (optional, but highly recommended), ensure dependencies are installed by running:\n\n```sh\nmake install\n```\n\nAfter developing, the full test suite can be evaluated by running:\n\n```sh\nmake lint\n# and\nmake test\n```\n\n# Notes\n\nThis package is heavily inspired in [jest snapshot testing](https://facebook.github.io/jest/docs/snapshot-testing.html).\n\n# Reasons to use this package\n\n> Most of this content is taken from the [Jest snapshot blogpost](https://facebook.github.io/jest/blog/2016/07/27/jest-14.html).\n\nWe want to make it as frictionless as possible to write good tests that are useful.\nWe observed that when engineers are provided with ready-to-use tools, they end up writing more tests, which in turn results in stable and healthy code bases.\n\nHowever engineers frequently spend more time writing a test than the component itself. As a result many people stopped writing tests altogether which eventually led to instabilities.\n\nA typical snapshot test case for a mobile app renders a UI component, takes a screenshot, then compares it to a reference image stored alongside the test. The test will fail if the two images do not match: either the change is unexpected, or the screenshot needs to be updated to the new version of the UI component.\n\n\n## Snapshot Testing with SnapshotTest\n\nA similar approach can be taken when it comes to testing your APIs.\nInstead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your API response.\n\n\n## License\n\n[MIT License](https://github.com/syrusakbary/snapshottest/blob/master/LICENSE)\n\n[![coveralls][coveralls-image]][coveralls-url]\n\n[coveralls-image]: https://coveralls.io/repos/syrusakbary/snapshottest/badge.svg?branch=master&service=github\n[coveralls-url]: https://coveralls.io/github/syrusakbary/snapshottest?branch=master\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Snapshot testing for pytest, unittest, Django, and Nose",
    "version": "0.6.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "56b2e7579cf37d3b2fe0cd2ef3791fbc",
                "sha256": "9b177cffe0870c589df8ddbee0a770149c5474b251955bdbde58b7f32a4ec429"
            },
            "downloads": -1,
            "filename": "snapshottest-0.6.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "56b2e7579cf37d3b2fe0cd2ef3791fbc",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 16510,
            "upload_time": "2020-09-29T03:54:49",
            "upload_time_iso_8601": "2020-09-29T03:54:49.735578Z",
            "url": "https://files.pythonhosted.org/packages/c9/d9/9527f609c28b508043edf587d03f96b8621ae4adaa4480197347cb640d0e/snapshottest-0.6.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "d9cdbe189ddab8d7bb2505ecd5c84044",
                "sha256": "bbcaf81d92d8e330042e5c928e13d9f035e99e91b314fe55fda949c2f17b653c"
            },
            "downloads": -1,
            "filename": "snapshottest-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d9cdbe189ddab8d7bb2505ecd5c84044",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 22573,
            "upload_time": "2020-09-29T03:54:51",
            "upload_time_iso_8601": "2020-09-29T03:54:51.005648Z",
            "url": "https://files.pythonhosted.org/packages/14/6a/6a6ff192326d79048f44c9348acad760070cce68f9fc9c9832c3efa7aca8/snapshottest-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-09-29 03:54:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "syrusakbary",
    "github_project": "snapshottest",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "snapshottest"
}
        
Elapsed time: 0.02120s