{ "info": { "author": "John Bjorn Nelson", "author_email": "jbn@abreka.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Framework :: Pytest", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Testing" ], "description": "=============\npytest-caprng\n=============\n\n.. image:: https://img.shields.io/pypi/v/pytest-caprng.svg\n :target: https://pypi.org/project/pytest-caprng\n :alt: PyPI version\n\n.. image:: https://img.shields.io/pypi/pyversions/pytest-caprng.svg\n :target: https://pypi.org/project/pytest-caprng\n :alt: Python versions\n\n.. image:: https://travis-ci.org/jbn/pytest-caprng.svg?branch=master\n :target: https://travis-ci.org/jbn/pytest-caprng\n :alt: See Build Status on Travis CI\n\n.. image:: https://ci.appveyor.com/api/projects/status/github/jbn/pytest-caprng?branch=master\n :target: https://ci.appveyor.com/project/jbn/pytest-caprng/branch/master\n :alt: See Build Status on AppVeyor\n\n\nA plugin that replays pRNG state on failure.\n\n----\n\nWhy is this?\n-------------\n\nTesting stochastic functions is challenging. Crudely, one of two things happens:\n\n1. *You learn to ignore sporadic failures.* For example, if you constructed a `binomial_test `_ over some stochastic function, there is some probability it will fail. Knowing this, you rerun the test; it works; you conclude there is no problem. Usually, that is the correct conclusion. But, repeating this pattern over and over will blind you to genuinely faulty code. This makes bug discovery less likely. This is bad.\n\n2. *You monkey patch your pRNG.* Usually, this means scheduling realizations, injecting determinism. But, this requires knowing the implementation details of the function your testing. And, if that changes, the test needs a change, too. This is fragile. This makes bug discovery less likely. This is bad.\n\nThis plugin is a compromise meant to eliminate (2) and reduce the prevalence of (1). It lends *some* degree of determinism to your tests by means of reproducibility. **If your stochastic test fails, rerunning it will result in the exact same failure**. \n\nHow it works?\n----------------\n\nUnless you have (cool) specialized hardware, your code doesn't use random numbers. Instead, it uses a deterministic sequences of numbers produced by a Pseudo Random Number Generator (PRNG) that is \"random enough.\" Each PRNG has an internal state. When you draw a sample, the state changes. If you reset the PRNG's state back to the original state, then sample again, the sample will be identical to the first one. It's deterministic.\n\nThis plugin exploits that determinism for the PRNGs underlying ``random`` and ``np.random``. Prior to each test function, caprng [cap]tures the p[rng] state. If the test fails, the plugin writes the captured state to the cache. Then, when you rerun the tests, the plugin looks to see if your test function has any associated, cached PRNG state. If it does, it overwrites PRNG state to *prior* to running the test function, **exactly reproducing the failing tests prior environment**.\n\n\nInstallation\n------------\n\nYou can install \"pytest-caprng\" via::\n\n $ pip install pytest-caprng\n\n\nUsage\n-----\n\nFor ``random``-based state capturing::\n\n $ pytest --caprng-global-stdlib\n\nAnd for ``np.random``::\n\n $ pytest --caprng-global-np\n\nYou probably should add the option to your pytest.ini file:\n\n [pytest]\n addopts = --caprng-global-stdlib --caprng-global-np\n\nso that you don't \"miss\" reproducible errors.\n\nContributing\n------------\nContributions are very welcome. Tests can be run with ``tox``, please ensure\nthe coverage at least stays the same before you submit a pull request.\n\nLicense\n-------\n\nDistributed under the terms of the MIT license, \"pytest-caprng\" is free and open source software\n\n\nIssues\n------\n\nIf you encounter any problems, please file an issue along with a detailed description.\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jbn/pytest-caprng", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pytest-caprng", "package_url": "https://pypi.org/project/pytest-caprng/", "platform": "", "project_url": "https://pypi.org/project/pytest-caprng/", "project_urls": { "Homepage": "https://github.com/jbn/pytest-caprng" }, "release_url": "https://pypi.org/project/pytest-caprng/0.1.0/", "requires_dist": null, "requires_python": "", "summary": "A plugin that replays pRNG state on failure.", "version": "0.1.0" }, "last_serial": 3827882, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "4eae57f594db1b1c10434e757419d9b7", "sha256": "ffdb9f5cd63293afc8e0959c26ba72cc6858c864c04b3e88dc72560c8736f0e0" }, "downloads": -1, "filename": "pytest-caprng-0.0.1.tar.gz", "has_sig": false, "md5_digest": "4eae57f594db1b1c10434e757419d9b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4055, "upload_time": "2018-04-27T00:27:27", "url": "https://files.pythonhosted.org/packages/f1/2c/1e5055874a99d2c090e86abb0752d12fee423793ddbb7ec74b1f4c63cfc4/pytest-caprng-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "88c821000c31a8be319116082d4fedaf", "sha256": "0f6d3c0d2502655644caaa683ca0556e1dbf5b1c43ba7fd95968594ab4894d3d" }, "downloads": -1, "filename": "pytest-caprng-0.0.2.tar.gz", "has_sig": false, "md5_digest": "88c821000c31a8be319116082d4fedaf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5293, "upload_time": "2018-04-28T23:38:44", "url": "https://files.pythonhosted.org/packages/62/00/e459d6c103d7f4d4aa39c507c288edb763ee7ba59eddfa2725b3822fab46/pytest-caprng-0.0.2.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "985b94ca1ac16673534e402afee3798b", "sha256": "e24970f8ab591f697817916dd82a38c94794d73b614993bbf395fe1b65b6b6ed" }, "downloads": -1, "filename": "pytest-caprng-0.1.0.tar.gz", "has_sig": false, "md5_digest": "985b94ca1ac16673534e402afee3798b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5294, "upload_time": "2018-05-02T17:29:00", "url": "https://files.pythonhosted.org/packages/ab/6c/9a0714556d90cae5612de4268eff0537240d74f24d4468c8dcec0b178c41/pytest-caprng-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "985b94ca1ac16673534e402afee3798b", "sha256": "e24970f8ab591f697817916dd82a38c94794d73b614993bbf395fe1b65b6b6ed" }, "downloads": -1, "filename": "pytest-caprng-0.1.0.tar.gz", "has_sig": false, "md5_digest": "985b94ca1ac16673534e402afee3798b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5294, "upload_time": "2018-05-02T17:29:00", "url": "https://files.pythonhosted.org/packages/ab/6c/9a0714556d90cae5612de4268eff0537240d74f24d4468c8dcec0b178c41/pytest-caprng-0.1.0.tar.gz" } ] }