pytest-datarecorder


Namepytest-datarecorder JSON
Version 1.7.0 PyPI version JSON
download
home_pagehttps://github.com/steinwurf/pytest-datarecorder
SummaryA py.test plugin recording and comparing test output.
upload_time2024-02-15 21:58:52
maintainer
docs_urlNone
authorSteinwurf ApS
requires_python
licenseBSD 3-clause "New" or "Revised" License
keywords pytest py.test testing unit tests plugin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ===================
pytest-datarecorder
===================

|PyPi| |Waf Python Tests| |Black| |Flake8| |Pip Install|

.. |PyPi| image:: https://badge.fury.io/py/pytest-datarecorder.svg
    :target: https://badge.fury.io/py/pytest-datarecorder

.. |Waf Python Tests| image:: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/python-waf.yml/badge.svg
   :target: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/python-waf.yml

.. |Flake8| image:: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/flake.yml/badge.svg
    :target: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/flake.yml

.. |Black| image:: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/black.yml/badge.svg
      :target: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/black.yml

.. |Pip Install| image:: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/pip.yml/badge.svg
      :target: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/pip.yml

Testing code that generates output can be tedious to maintain
 ``pytest-datarecorder`` aims to simplify this task.

.. contents:: Table of Contents:
   :local:

Installation
============

To install pytest-datarecorder::

    pip install pytest-datarecorder

Usage
=====

To make it easy to use in with py.test the DataRecorder object can be
injected into a test function by using the datarecorder fixture.

Example::

    def test_this_function(datarecorder):

        datarecorder.record_data(
            data={'a':1, 'b':2}, recording_file="test/data/recording.json")

The ``data`` passed will be serialized to JSON since the recording file
has a ``.json`` extension. If ``data`` changes, we will get an exception
containing a diff with what changed. If we want to accept the changes
we simply delete the recording and run the code again.

Relase new version
==================

1. Edit NEWS.rst and wscript (set correct VERSION)
2. Run ::

    ./waf upload

Source code
===========

The main functionality is found in ``src/datarecorder.py`` and the
corresponding unit test is in ``test/test_datarecorder.py`` if you
want to play/modify/fix the code this would, in most cases, be the place
to start.

Developer Notes
===============

We try to make our projects as independent as possible of a local system setup.
For example with our native code (C/C++) we compile as much as possible from
source, since this makes us independent of what is currently installed
(libraries etc.) on a specific machine.

To "fetch" sources we use Waf (https://waf.io/) augmented with dependency
resolution capabilities: https://github.com/steinwurf/waf

The goal is to enable a work-flow where running::

    ./waf configure
    ./waf build --run_tests

Configures, builds and runs any available tests for a given project, such that
you as a developer can start hacking at the code.

For Python project this is a bit unconventional, but we think it works well.

Tests
=====

The tests will run automatically by passing ``--run_tests`` to waf::

    ./waf --run_tests

This follows what seems to be "best practice" advise, namely to install the
package in editable mode in a virtualenv.

Notes
=====

* Why use an ``src`` folder (https://hynek.me/articles/testing-packaging/).
  tl;dr you should run your tests in the same environment as your users would
  run your code. So by placing the source files in a non-importable folder you
  avoid accidentally having access to resources not added to the Python
  package your users will install...
* Python packaging guide: https://packaging.python.org/distributing/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/steinwurf/pytest-datarecorder",
    "name": "pytest-datarecorder",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pytest py.test testing unit tests plugin",
    "author": "Steinwurf ApS",
    "author_email": "contact@steinwurf.com",
    "download_url": "",
    "platform": null,
    "description": "===================\npytest-datarecorder\n===================\n\n|PyPi| |Waf Python Tests| |Black| |Flake8| |Pip Install|\n\n.. |PyPi| image:: https://badge.fury.io/py/pytest-datarecorder.svg\n    :target: https://badge.fury.io/py/pytest-datarecorder\n\n.. |Waf Python Tests| image:: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/python-waf.yml/badge.svg\n   :target: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/python-waf.yml\n\n.. |Flake8| image:: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/flake.yml/badge.svg\n    :target: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/flake.yml\n\n.. |Black| image:: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/black.yml/badge.svg\n      :target: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/black.yml\n\n.. |Pip Install| image:: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/pip.yml/badge.svg\n      :target: https://github.com/steinwurf/pytest-datarecorder/actions/workflows/pip.yml\n\nTesting code that generates output can be tedious to maintain\n ``pytest-datarecorder`` aims to simplify this task.\n\n.. contents:: Table of Contents:\n   :local:\n\nInstallation\n============\n\nTo install pytest-datarecorder::\n\n    pip install pytest-datarecorder\n\nUsage\n=====\n\nTo make it easy to use in with py.test the DataRecorder object can be\ninjected into a test function by using the datarecorder fixture.\n\nExample::\n\n    def test_this_function(datarecorder):\n\n        datarecorder.record_data(\n            data={'a':1, 'b':2}, recording_file=\"test/data/recording.json\")\n\nThe ``data`` passed will be serialized to JSON since the recording file\nhas a ``.json`` extension. If ``data`` changes, we will get an exception\ncontaining a diff with what changed. If we want to accept the changes\nwe simply delete the recording and run the code again.\n\nRelase new version\n==================\n\n1. Edit NEWS.rst and wscript (set correct VERSION)\n2. Run ::\n\n    ./waf upload\n\nSource code\n===========\n\nThe main functionality is found in ``src/datarecorder.py`` and the\ncorresponding unit test is in ``test/test_datarecorder.py`` if you\nwant to play/modify/fix the code this would, in most cases, be the place\nto start.\n\nDeveloper Notes\n===============\n\nWe try to make our projects as independent as possible of a local system setup.\nFor example with our native code (C/C++) we compile as much as possible from\nsource, since this makes us independent of what is currently installed\n(libraries etc.) on a specific machine.\n\nTo \"fetch\" sources we use Waf (https://waf.io/) augmented with dependency\nresolution capabilities: https://github.com/steinwurf/waf\n\nThe goal is to enable a work-flow where running::\n\n    ./waf configure\n    ./waf build --run_tests\n\nConfigures, builds and runs any available tests for a given project, such that\nyou as a developer can start hacking at the code.\n\nFor Python project this is a bit unconventional, but we think it works well.\n\nTests\n=====\n\nThe tests will run automatically by passing ``--run_tests`` to waf::\n\n    ./waf --run_tests\n\nThis follows what seems to be \"best practice\" advise, namely to install the\npackage in editable mode in a virtualenv.\n\nNotes\n=====\n\n* Why use an ``src`` folder (https://hynek.me/articles/testing-packaging/).\n  tl;dr you should run your tests in the same environment as your users would\n  run your code. So by placing the source files in a non-importable folder you\n  avoid accidentally having access to resources not added to the Python\n  package your users will install...\n* Python packaging guide: https://packaging.python.org/distributing/\n",
    "bugtrack_url": null,
    "license": "BSD 3-clause \"New\" or \"Revised\" License",
    "summary": "A py.test plugin recording and comparing test output.",
    "version": "1.7.0",
    "project_urls": {
        "Homepage": "https://github.com/steinwurf/pytest-datarecorder"
    },
    "split_keywords": [
        "pytest",
        "py.test",
        "testing",
        "unit",
        "tests",
        "plugin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0e8180322c1b4b91a6f43deb91884edb40d78e1820cae25d158ff2ac95aed562",
                "md5": "ef8414e4852614203a0cc2665ad2c025",
                "sha256": "ab5f22a3164e4de58dbef6819e164037512ef19acc254accfb46e991c918b912"
            },
            "downloads": -1,
            "filename": "pytest_datarecorder-1.7.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ef8414e4852614203a0cc2665ad2c025",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 7459,
            "upload_time": "2024-02-15T21:58:52",
            "upload_time_iso_8601": "2024-02-15T21:58:52.757735Z",
            "url": "https://files.pythonhosted.org/packages/0e/81/80322c1b4b91a6f43deb91884edb40d78e1820cae25d158ff2ac95aed562/pytest_datarecorder-1.7.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-15 21:58:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "steinwurf",
    "github_project": "pytest-datarecorder",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "appveyor": true,
    "lcname": "pytest-datarecorder"
}
        
Elapsed time: 0.19110s