{"id":19657743,"url":"https://github.com/esss/pytest-replay","last_synced_at":"2025-04-28T19:32:22.468Z","repository":{"id":29693365,"uuid":"122505629","full_name":"ESSS/pytest-replay","owner":"ESSS","description":"Saves runs to allow to re-execute previous pytest runs to reproduce crashes or flaky tests","archived":false,"fork":false,"pushed_at":"2024-04-30T11:12:23.000Z","size":118,"stargazers_count":47,"open_issues_count":0,"forks_count":3,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-04-30T18:04:11.104Z","etag":null,"topics":["hacktoberfest","pytest"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ESSS.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-22T16:38:48.000Z","updated_at":"2024-06-03T19:19:16.656Z","dependencies_parsed_at":"2024-02-20T12:31:45.218Z","dependency_job_id":"80546158-3507-4756-9f14-d3a372794786","html_url":"https://github.com/ESSS/pytest-replay","commit_stats":{"total_commits":103,"total_committers":7,"mean_commits":"14.714285714285714","dds":0.6504854368932038,"last_synced_commit":"c6dbfee2004d2adfddd9754c5b844e8aaf7c30bb"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ESSS%2Fpytest-replay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ESSS%2Fpytest-replay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ESSS%2Fpytest-replay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ESSS%2Fpytest-replay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ESSS","download_url":"https://codeload.github.com/ESSS/pytest-replay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251375507,"owners_count":21579457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","pytest"],"created_at":"2024-11-11T15:33:31.198Z","updated_at":"2025-04-28T19:32:22.461Z","avatar_url":"https://github.com/ESSS.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=============\npytest-replay\n=============\n\n\n.. image:: http://img.shields.io/pypi/v/pytest-replay.svg\n    :target: https://pypi.python.org/pypi/pytest-replay\n\n.. image:: https://anaconda.org/conda-forge/pytest-replay/badges/version.svg\n    :target: https://anaconda.org/conda-forge/pytest-replay\n\n.. image:: https://github.com/ESSS/pytest-replay/workflows/test/badge.svg\n    :target: https://github.com/ESSS/pytest-replay/actions?query=workflow%3Atest\n\n.. image:: https://img.shields.io/pypi/pyversions/pytest-replay.svg\n    :target: https://pypi.python.org/pypi/pytest-replay\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n\n\nSaves previous test runs and allow re-execute previous pytest runs to reproduce crashes or flaky tests\n\n----\n\nThis `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template.\n\n\nFeatures\n--------\n\nThis plugin helps to reproduce random or flaky behavior when running tests with xdist. ``pytest-xdist`` executes tests\nin a non-predictable order, making it hard to reproduce a behavior seen in CI locally because there's no convenient way\nto track which test executed in which worker.\n\nThis plugin records the executed node ids by each worker in the directory given by ``--replay-record-dir=\u003cdir\u003e`` flag,\nand a ``--replay=\u003cfile\u003e`` can be used to re-run the tests from a previous run. For example::\n\n    $ pytest -n auto --replay-record-dir=build/tests/replay\n\nThis will generate files with each line being a ``json`` with the following content:\nnode identification, start time, end time and outcome. It is interesting to note\nthat usually the node id is repeated twice, that is necessary in case of a test\nsuddenly crashes we will still have the record of that test started. After the\ntest finishes, ``pytest-replay`` will add another ``json`` line with the\ncomplete information.\nThat is also useful to analyze concurrent tests which might have some kind of\nrace condition and interfere in each other.\n\nFor example worker ``gw1`` will generate a file\n``.pytest-replay-gw1.txt`` with contents like this::\n\n    {\"nodeid\": \"test_foo.py::test[1]\", \"start\": 0.000}\n    {\"nodeid\": \"test_foo.py::test[1]\", \"start\": 0.000, \"finish\": 1.5, \"outcome\": \"passed\"}\n    {\"nodeid\": \"test_foo.py::test[3]\", \"start\": 1.5}\n    {\"nodeid\": \"test_foo.py::test[3]\", \"start\": 1.5, \"finish\": 2.5, \"outcome\": \"passed\"}\n    {\"nodeid\": \"test_foo.py::test[5]\", \"start\": 2.5}\n    {\"nodeid\": \"test_foo.py::test[5]\", \"start\": 2.5, \"finish\": 3.5, \"outcome\": \"passed\"}\n    {\"nodeid\": \"test_foo.py::test[7]\", \"start\": 3.5}\n    {\"nodeid\": \"test_foo.py::test[7]\", \"start\": 3.5, \"finish\": 4.5, \"outcome\": \"passed\"}\n    {\"nodeid\": \"test_foo.py::test[8]\", \"start\": 4.5}\n    {\"nodeid\": \"test_foo.py::test[8]\", \"start\": 4.5, \"finish\": 5.5, \"outcome\": \"passed\"}\n\n\nIf there is a crash or a flaky failure in the tests of the worker ``gw1``, one can take that file from the CI server and\nexecute the tests in the same order with::\n\n    $ pytest --replay=.pytest-replay-gw1.txt\n\nHopefully this will make it easier to reproduce the problem and fix it.\n\nAdditional metadata\n-------------------\n\n*Version added: 1.6*\n\nIn cases where it is necessary to add new metadata to the replay file to make the test reproducible, `pytest-replay`\nprovides a fixture called ``replay_metadata`` that allows new information to be added using the ``metadata``\nattribute.\n\nExample:\n\n.. code-block:: python\n\n    import pytest\n    import numpy as np\n    import random\n\n    @pytest.fixture\n    def rng(replay_metadata):\n        seed = replay_metadata.metadata.setdefault(\"seed\", random.randint(0, 100))\n        return np.random.default_rng(seed=seed)\n\n    def test_random(rng):\n        data = rng.standard_normal((100, 100))\n        assert data.shape == (100, 100)\n\n\nWhen using it with pytest-replay it generates a replay file similar to\n\n.. code-block:: json\n\n    {\"nodeid\": \"test_bar.py::test_random\", \"start\": 0.000}\n    {\"nodeid\": \"test_bar.py::test_random\", \"start\": 0.000, \"finish\": 1.5, \"outcome\": \"passed\", \"metadata\": {\"seed\": 12}}\n\n\nFAQ\n~~~\n\n1. ``pytest`` has its own `cache \u003chttps://docs.pytest.org/en/latest/cache.html\u003e`_, why use a different mechanism?\n\n   The internal cache saves its data using ``json``, which is not suitable in the advent of a crash because the file\n   will not be readable.\n\n2. Shouldn't the ability of selecting tests from a file be part of the ``pytest`` core?\n\n   Sure, but let's try to use this a bit as a separate plugin before proposing\n   its inclusion into the core.\n\nInstallation\n------------\n\nYou can install ``pytest-replay`` via `pip`_ from `PyPI`_::\n\n    $ pip install pytest-replay\n\nOr with conda::\n\n    $ conda install -c conda-forge pytest-replay\n\n\nContributing\n------------\n\nContributions are very welcome.\n\nTests can be run with `tox`_ if you are using a native Python installation.\n\nTo run tests with `conda \u003chttps://conda.io/docs/\u003e`_, first create a virtual environment and execute tests from there\n(conda with Python 3.5+ in the root environment)::\n\n    $ python -m venv .env\n    $ .env\\scripts\\activate\n    $ pip install -e . pytest-xdist\n    $ pytest tests\n\n\nReleases\n~~~~~~~~\n\nFollow these steps to make a new release:\n\n1. Create a new branch ``release-X.Y.Z`` from ``master``;\n2. Update ``CHANGELOG.rst``;\n3. Open a PR;\n4. After it is **green** and **approved**, push a new tag in the format ``X.Y.Z``;\n\nGitHub Actions will deploy to PyPI automatically.\n\nAfterwards, update the recipe in `conda-forge/pytest-replay-feedstock \u003chttps://github.com/conda-forge/pytest-replay-feedstock\u003e`_.\n\n\nLicense\n-------\n\nDistributed under the terms of the `MIT`_ license.\n\n\nIssues\n------\n\nIf you encounter any problems, please `file an issue`_ along with a detailed description.\n\n.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter\n.. _`@hackebrot`: https://github.com/hackebrot\n.. _`MIT`: http://opensource.org/licenses/MIT\n.. _`BSD-3`: http://opensource.org/licenses/BSD-3-Clause\n.. _`GNU GPL v3.0`: http://www.gnu.org/licenses/gpl-3.0.txt\n.. _`Apache Software License 2.0`: http://www.apache.org/licenses/LICENSE-2.0\n.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin\n.. _`file an issue`: https://github.com/ESSS/pytest-replay/issues\n.. _`pytest`: https://github.com/pytest-dev/pytest\n.. _`tox`: https://tox.readthedocs.io/en/latest/\n.. _`pip`: https://pypi.python.org/pypi/pip/\n.. _`PyPI`: https://pypi.python.org/pypi\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesss%2Fpytest-replay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesss%2Fpytest-replay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesss%2Fpytest-replay/lists"}