pytest-find-dependencies


Namepytest-find-dependencies JSON
Version 0.6.0 PyPI version JSON
download
home_pageNone
SummaryA pytest plugin to find dependencies between tests
upload_time2025-07-16 19:08:30
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords testing pytest dependencies
VCS
bugtrack_url
requirements pytest
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ========================
pytest-find-dependencies
========================

.. image:: https://img.shields.io/pypi/v/pytest-find-dependencies.svg
    :target: https://pypi.org/project/pytest-find-dependencies
    :alt: PyPI version

.. image:: https://img.shields.io/pypi/pyversions/pytest-find-dependencies.svg
    :target: https://pypi.org/project/pytest-find-dependencies
    :alt: Python versions

.. image:: https://github.com/mrbean-bremen/pytest-find-dependencies/workflows/Testsuite/badge.svg
    :target: https://github.com/mrbean-bremen/pytest-find-dependencies/actions?query=workflow%3ATestsuite
    :alt: Test suite

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit
   :target: https://github.com/mrbean-bremen/pytest-find-dependencies
   :alt: pre-commit

.. image:: https://codecov.io/gh/mrbean-bremen/pytest-find-dependencies/branch/main/graph/badge.svg
    :target: https://codecov.io/gh/mrbean-bremen/pytest-find-dependencies
    :alt: Code coverage

.. image:: https://img.shields.io/pypi/dw/pytest-find-dependencies
   :alt: PyPI - Downloads

A pytest plugin to find dependencies between tests.

----

This `pytest`_ plugin was generated with `Cookiecutter`_ along with
`@hackebrot`_'s `cookiecutter-pytest-plugin`_ template.


Summary
-------

Tests shall generally not depend on each other. To ensure this, plugins
like `pytest-randomly`_ or  `pytest-reverse`_ are commonly used. These
plugins find dependent tests, but it is up to you to find which test they
are depend upon.

The plugin aims to automate this task. Dependencies are found
in the first place by running all tests in forward and backwards direction
and checking if any tests fail if executed in one order but not in the other.
This will find most (but not all) test dependencies (the same way as
`pytest-reverse`_). If any dependent test is found, more test runs with
a subset of all tests are run using binary search, until a test is found
that causes the other test to fail.

.. note::
   I recently found out that there exists now another pytest plugin with similar
   functionality, but with far better documentation, that is also far more popular:
   `detect-test-pollution`_ by Anthony Sottile. I will continue to use and develop
   ``pytest-find-dependencies``, and certainly react to any issues or feature requests,
   but encourage you to try out that project instead.

Installation
------------

You can install ``pytest-find-dependencies`` via `pip`_ from `PyPI`_::

    $ pip install pytest-find-dependencies

Usage
-----
If the plugin is installed, it can be used by adding the pytest option
``--find-dependencies``. After running all needed tests, all found
dependencies are listed. Here is an example::

    =================================================
    Run dependency analysis for 7 tests.
    Executed 19 tests in 4 test runs.
    Dependent tests:
    test_one.py::test_b depends on test_one.py::test_e
    =================================================

In this case 7 tests have been analyzed, one dependent test has been found
after running the tests forwards and backwards, and after 2 additional test
runs with an overall of 5 tests, the test it depended on was found.

Some dependencies can be due to a permanent change in the environment (for
example by adding a change to a database that is not reverted in subsequent
test runs). In this case, the dependency cannot be found reliably, and these
tests are listed separately::

    ============================== Results ===============================
    Run dependency analysis for 5 tests.
    Executed 11 tests in 3 test runs.
    Tests failing permanently after all tests have run:
    test_one.py::test_b
    ======================================================================

Dependencies due to a permanent change will only be found if the offending
test is run before the dependent test, otherwise the test will just fail both
times.

Options
-------

``--run-serially``
~~~~~~~~~~~~~~~~~~
By default, the forward and reversed test runs are executed in parallel in
separate processes. The option ``--run-serially`` allows to change this
behavior to run all tests sequentially. This increases the overall runtime,
but sometimes may reveal permanent changes not reliably found in the default
mode.

``--reversed-first``
~~~~~~~~~~~~~~~~~~~~
This option allows you to reverse the sequence of the first two test runs.
Note that it only makes sense in combination with ``--run-serially``, as per
default these test runs are executed in parallel.

``--fail-on-failed-tests``
~~~~~~~~~~~~~~~~~~~~~~~~~~
Per default, the dependency test only returns the exit code 1, if any
dependency has been found, otherwise 0. This option changes this behavior -
any failing test will also fail the dependency test (e.g. the exit code will be 1).

``--markers-to-ignore``
~~~~~~~~~~~~~~~~~~~~~~~
This option allows to define a comma-separated list of marker names. Tests that
have these markers will be ignored in the analysis (e.g. not run at all).
This can be used to exclude tests that have markers that define the test order.
Examples include ``dependency`` (from the ``pytest-dependency`` plugin), ``order``
(from ``pytest-order``) or ``depends`` (from ``pytest-depends``). To ignore all
tests with a ``dependency`` marker, you can use::

  python -m pytest --find-dependencies --markers-to-ignore=dependency

Note that in this case you also won't find other tests depending on the
ordered markers.

Notes
-----
- command line options given in the test are passed to all test runs
  in dependency find mode
- if any dependent tests are found, the exit code of the pytest run will be
  set to 1, see also the option ``--fail-on-failed-tests`` above
- if ``pytest-xdist`` is detected, it is ensured that the internal tests
  are *not* distributed, as this would break the dependency check
- if no dependent tests are found, the test will run a bit longer than the original
  tests (without xdist), with the option ``--run-serially`` about twice as long;
  with one dependent test it will take about 1.5 times as long as the original tests, and with
  each found dependent test it will take more time (due to more repeated tests)

Usage of ordering plugins
-------------------------
If you use plugins which change the test order using markers, these will only
be applied in the first test run. The order of the following test runs is
solely defined by ``pytest-find-dependencies``. This means that if you use
ordering plugins like ``pytest-order``, the dependencies will still be
found, if you don't exclude these tests (which may or may not be wanted).
Using ``pytest-randomly`` will randomize only the first test run and can be used
in combination with ``pytest-find-dependencies`` without problems.

Contributing
------------
Contributions are very welcome. Tests can be run with `tox`_, please ensure
the coverage at least stays the same before you submit a pull request.

License
-------
Distributed under the terms of the `MIT`_ license,
"pytest-find-dependencies" is free and open source software.

Issues
------
If you encounter any problems or have a feature request, please
`file an issue`_ along with a detailed description.

.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter
.. _`@hackebrot`: https://github.com/hackebrot
.. _`MIT`: http://opensource.org/licenses/MIT
.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin
.. _`file an issue`: https://github.com/mrbean-bremen/pytest-find-dependencies/issues
.. _`pytest`: https://github.com/pytest-dev/pytest
.. _`tox`: https://tox.readthedocs.io/en/latest/
.. _`pip`: https://pypi.org/project/pip/
.. _`PyPI`: https://pypi.org/project
.. _`pytest-randomly`: https://github.com/pytest-dev/pytest-randomly
.. _`pytest-reverse`: https://github.com/adamchainz/pytest-reverse
.. _`detect-test-pollution`: https://github.com/asottile/detect-test-pollution

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytest-find-dependencies",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "testing, pytest, dependencies",
    "author": null,
    "author_email": "mrbean-bremen <hansemrbean@googlemail.com>",
    "download_url": "https://files.pythonhosted.org/packages/5e/8a/378f07e9fe4779622d6cac934c98b133ec3f376a49f82b0b88cecb0aa3a5/pytest_find_dependencies-0.6.0.tar.gz",
    "platform": null,
    "description": "========================\npytest-find-dependencies\n========================\n\n.. image:: https://img.shields.io/pypi/v/pytest-find-dependencies.svg\n    :target: https://pypi.org/project/pytest-find-dependencies\n    :alt: PyPI version\n\n.. image:: https://img.shields.io/pypi/pyversions/pytest-find-dependencies.svg\n    :target: https://pypi.org/project/pytest-find-dependencies\n    :alt: Python versions\n\n.. image:: https://github.com/mrbean-bremen/pytest-find-dependencies/workflows/Testsuite/badge.svg\n    :target: https://github.com/mrbean-bremen/pytest-find-dependencies/actions?query=workflow%3ATestsuite\n    :alt: Test suite\n\n.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\n   :target: https://github.com/mrbean-bremen/pytest-find-dependencies\n   :alt: pre-commit\n\n.. image:: https://codecov.io/gh/mrbean-bremen/pytest-find-dependencies/branch/main/graph/badge.svg\n    :target: https://codecov.io/gh/mrbean-bremen/pytest-find-dependencies\n    :alt: Code coverage\n\n.. image:: https://img.shields.io/pypi/dw/pytest-find-dependencies\n   :alt: PyPI - Downloads\n\nA pytest plugin to find dependencies between tests.\n\n----\n\nThis `pytest`_ plugin was generated with `Cookiecutter`_ along with\n`@hackebrot`_'s `cookiecutter-pytest-plugin`_ template.\n\n\nSummary\n-------\n\nTests shall generally not depend on each other. To ensure this, plugins\nlike `pytest-randomly`_ or  `pytest-reverse`_ are commonly used. These\nplugins find dependent tests, but it is up to you to find which test they\nare depend upon.\n\nThe plugin aims to automate this task. Dependencies are found\nin the first place by running all tests in forward and backwards direction\nand checking if any tests fail if executed in one order but not in the other.\nThis will find most (but not all) test dependencies (the same way as\n`pytest-reverse`_). If any dependent test is found, more test runs with\na subset of all tests are run using binary search, until a test is found\nthat causes the other test to fail.\n\n.. note::\n   I recently found out that there exists now another pytest plugin with similar\n   functionality, but with far better documentation, that is also far more popular:\n   `detect-test-pollution`_ by Anthony Sottile. I will continue to use and develop\n   ``pytest-find-dependencies``, and certainly react to any issues or feature requests,\n   but encourage you to try out that project instead.\n\nInstallation\n------------\n\nYou can install ``pytest-find-dependencies`` via `pip`_ from `PyPI`_::\n\n    $ pip install pytest-find-dependencies\n\nUsage\n-----\nIf the plugin is installed, it can be used by adding the pytest option\n``--find-dependencies``. After running all needed tests, all found\ndependencies are listed. Here is an example::\n\n    =================================================\n    Run dependency analysis for 7 tests.\n    Executed 19 tests in 4 test runs.\n    Dependent tests:\n    test_one.py::test_b depends on test_one.py::test_e\n    =================================================\n\nIn this case 7 tests have been analyzed, one dependent test has been found\nafter running the tests forwards and backwards, and after 2 additional test\nruns with an overall of 5 tests, the test it depended on was found.\n\nSome dependencies can be due to a permanent change in the environment (for\nexample by adding a change to a database that is not reverted in subsequent\ntest runs). In this case, the dependency cannot be found reliably, and these\ntests are listed separately::\n\n    ============================== Results ===============================\n    Run dependency analysis for 5 tests.\n    Executed 11 tests in 3 test runs.\n    Tests failing permanently after all tests have run:\n    test_one.py::test_b\n    ======================================================================\n\nDependencies due to a permanent change will only be found if the offending\ntest is run before the dependent test, otherwise the test will just fail both\ntimes.\n\nOptions\n-------\n\n``--run-serially``\n~~~~~~~~~~~~~~~~~~\nBy default, the forward and reversed test runs are executed in parallel in\nseparate processes. The option ``--run-serially`` allows to change this\nbehavior to run all tests sequentially. This increases the overall runtime,\nbut sometimes may reveal permanent changes not reliably found in the default\nmode.\n\n``--reversed-first``\n~~~~~~~~~~~~~~~~~~~~\nThis option allows you to reverse the sequence of the first two test runs.\nNote that it only makes sense in combination with ``--run-serially``, as per\ndefault these test runs are executed in parallel.\n\n``--fail-on-failed-tests``\n~~~~~~~~~~~~~~~~~~~~~~~~~~\nPer default, the dependency test only returns the exit code 1, if any\ndependency has been found, otherwise 0. This option changes this behavior -\nany failing test will also fail the dependency test (e.g. the exit code will be 1).\n\n``--markers-to-ignore``\n~~~~~~~~~~~~~~~~~~~~~~~\nThis option allows to define a comma-separated list of marker names. Tests that\nhave these markers will be ignored in the analysis (e.g. not run at all).\nThis can be used to exclude tests that have markers that define the test order.\nExamples include ``dependency`` (from the ``pytest-dependency`` plugin), ``order``\n(from ``pytest-order``) or ``depends`` (from ``pytest-depends``). To ignore all\ntests with a ``dependency`` marker, you can use::\n\n  python -m pytest --find-dependencies --markers-to-ignore=dependency\n\nNote that in this case you also won't find other tests depending on the\nordered markers.\n\nNotes\n-----\n- command line options given in the test are passed to all test runs\n  in dependency find mode\n- if any dependent tests are found, the exit code of the pytest run will be\n  set to 1, see also the option ``--fail-on-failed-tests`` above\n- if ``pytest-xdist`` is detected, it is ensured that the internal tests\n  are *not* distributed, as this would break the dependency check\n- if no dependent tests are found, the test will run a bit longer than the original\n  tests (without xdist), with the option ``--run-serially`` about twice as long;\n  with one dependent test it will take about 1.5 times as long as the original tests, and with\n  each found dependent test it will take more time (due to more repeated tests)\n\nUsage of ordering plugins\n-------------------------\nIf you use plugins which change the test order using markers, these will only\nbe applied in the first test run. The order of the following test runs is\nsolely defined by ``pytest-find-dependencies``. This means that if you use\nordering plugins like ``pytest-order``, the dependencies will still be\nfound, if you don't exclude these tests (which may or may not be wanted).\nUsing ``pytest-randomly`` will randomize only the first test run and can be used\nin combination with ``pytest-find-dependencies`` without problems.\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-------\nDistributed under the terms of the `MIT`_ license,\n\"pytest-find-dependencies\" is free and open source software.\n\nIssues\n------\nIf you encounter any problems or have a feature request, please\n`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.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin\n.. _`file an issue`: https://github.com/mrbean-bremen/pytest-find-dependencies/issues\n.. _`pytest`: https://github.com/pytest-dev/pytest\n.. _`tox`: https://tox.readthedocs.io/en/latest/\n.. _`pip`: https://pypi.org/project/pip/\n.. _`PyPI`: https://pypi.org/project\n.. _`pytest-randomly`: https://github.com/pytest-dev/pytest-randomly\n.. _`pytest-reverse`: https://github.com/adamchainz/pytest-reverse\n.. _`detect-test-pollution`: https://github.com/asottile/detect-test-pollution\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A pytest plugin to find dependencies between tests",
    "version": "0.6.0",
    "project_urls": {
        "changelog": "https://github.com/mrbean-bremen/pytest-find-dependencies/blob/main/CHANGELOG.rst",
        "homepage": "https://github.com/mrbean-bremen/pytest-find-dependencies",
        "issues": "https://github.com/mrbean-bremen/pytest-find-dependencies/issues",
        "repository": "https://github.com/mrbean-bremen/pytest-find-dependencies"
    },
    "split_keywords": [
        "testing",
        " pytest",
        " dependencies"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d8c845d6fd35753ae290a5d3b7627c38370d1232f9d577f8cea8e54ec573fab5",
                "md5": "9841842f3e375c1f8d182b66a46f4586",
                "sha256": "6aa3f612742e5b3d6e7bf265943b3997f9b9d3f5e89ef75f944c597fbc590426"
            },
            "downloads": -1,
            "filename": "pytest_find_dependencies-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9841842f3e375c1f8d182b66a46f4586",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9724,
            "upload_time": "2025-07-16T19:08:29",
            "upload_time_iso_8601": "2025-07-16T19:08:29.327815Z",
            "url": "https://files.pythonhosted.org/packages/d8/c8/45d6fd35753ae290a5d3b7627c38370d1232f9d577f8cea8e54ec573fab5/pytest_find_dependencies-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5e8a378f07e9fe4779622d6cac934c98b133ec3f376a49f82b0b88cecb0aa3a5",
                "md5": "e37ca0ab2e9a59615de8ef001302da45",
                "sha256": "4fe28781d4478b01bd52baac3d77a2cba5f8441a420e847059bbaadad86aab64"
            },
            "downloads": -1,
            "filename": "pytest_find_dependencies-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e37ca0ab2e9a59615de8ef001302da45",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 15386,
            "upload_time": "2025-07-16T19:08:30",
            "upload_time_iso_8601": "2025-07-16T19:08:30.393577Z",
            "url": "https://files.pythonhosted.org/packages/5e/8a/378f07e9fe4779622d6cac934c98b133ec3f376a49f82b0b88cecb0aa3a5/pytest_find_dependencies-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-16 19:08:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mrbean-bremen",
    "github_project": "pytest-find-dependencies",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pytest",
            "specs": [
                [
                    ">=",
                    "6.2.4"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "pytest-find-dependencies"
}
        
Elapsed time: 0.40892s