pytest-only


Namepytest-only JSON
Version 2.1.1 PyPI version JSON
download
home_pagehttps://github.com/theY4Kman/pytest-only
SummaryUse @pytest.mark.only to run a single test
upload_time2024-03-09 18:01:18
maintainer
docs_urlNone
authorZach Kanzler
requires_python>=3.7.2,<4
licenseMIT
keywords pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pytest-only
===========

Only run tests marked with ``@pytest.mark.only``. If none are marked, all tests run as usual.

Borrowed from `mocha <https://mochajs.org/>`_.


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

.. code-block:: bash

    pip install pytest-only


Usage
-----

Use it on functions

.. code-block:: python

    import pytest

    def test_that_will_not_run():
        assert 0

    @pytest.mark.only
    def test_that_will_run():
        assert 1


.. code-block:: bash

    $ py.test -v test_example.py

    ============================= test session starts ==============================
    platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6
    cachedir: .cache
    rootdir: /tmp/example, inifile:
    plugins: only-1.0.0
    collected 2 items

    test_example.py::test_that_will_run PASSED

    =========================== 1 passed in 0.00 seconds ===========================


Or use it on classes

.. code-block:: python

    import pytest

    class TestThatWillNotRun:
        def test_that_will_not_run(self):
            assert 0


    @pytest.mark.only
    class TestThatWillRun:
        def test_that_will_run(self):
            assert 1


.. code-block:: bash

    $ py.test -v test_example.py

    ============================= test session starts ==============================
    platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6
    cachedir: .cache
    rootdir: /tmp/example, inifile:
    plugins: only-1.0.0
    collected 2 items

    test_example.py::TestThatWillRun::test_that_will_run PASSED

    =========================== 1 passed in 0.00 seconds ===========================


Or use it on modules

.. code-block:: python

    # test_example.py
    import pytest

    pytestmark = pytest.mark.only

    def test_that_will_run():
        assert 1


.. code-block:: python

    # test_example2.py
    def test_that_will_not_run():
        assert 0


.. code-block:: bash

    $ py.test -v test_example.py test_example2.py

    ============================= test session starts ==============================
    platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28/bin/python3.6
    cachedir: .cache
    rootdir: /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28, inifile:
    plugins: only-1.0.0
    collected 2 items

    test_example.py::test_that_will_run PASSED

    =========================== 1 passed in 0.00 seconds ===========================



Disable for single test run
---------------------------

To run all the tests, regardless of whether ``@pytest.mark.only`` is used, pass
the ``--no-only`` flag to pytest:

.. code-block:: bash

    $ py.test --no-only


If ``--no-only`` has already been passed (perhaps by way of ``addopts`` in
*pytest.ini*), use the ``--only`` flag to re-enable it:

.. code-block:: bash

    $ py.test --no-only --only


Pylint checker
--------------

If you use pylint, you can avoid committing stray `only` marks with the bundled plugin. Just enable the pylint checker in your plugins and enable the `unexpected-focused` rule.

.. code-block:: ini

    [MASTER]
    load-plugins=pytest_only.ext.pylint

    [MESSAGES CONTROL]
    enable=unexpected-focused

.. code-block:: console

    $ cat test_ninja.py
    import pytest

    @pytest.mark.only
    def test_ninja():
        pass

    $ pylint test_ninja.py
    ************* Module mymain
    test_ninja.py:3:0: W1650: Unexpected focused test(s) using pytest.mark.only: def test_ninja (unexpected-focused)


Development
-----------

1. Install the test/dev requirements using `Poetry <https://python-poetry.org/>`_

    .. code-block:: bash

        poetry install

2. Run the tests

    .. code-block:: bash

        py.test

3. Run the tests on all currently-supported platforms

    .. code-block:: bash

        tox

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/theY4Kman/pytest-only",
    "name": "pytest-only",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7.2,<4",
    "maintainer_email": "",
    "keywords": "pytest",
    "author": "Zach Kanzler",
    "author_email": "they4kman@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/35/5c/8772432474700a9f784776dd22ae471c33f077a06cd56884cd1a176c4d18/pytest_only-2.1.1.tar.gz",
    "platform": null,
    "description": "pytest-only\n===========\n\nOnly run tests marked with ``@pytest.mark.only``. If none are marked, all tests run as usual.\n\nBorrowed from `mocha <https://mochajs.org/>`_.\n\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    pip install pytest-only\n\n\nUsage\n-----\n\nUse it on functions\n\n.. code-block:: python\n\n    import pytest\n\n    def test_that_will_not_run():\n        assert 0\n\n    @pytest.mark.only\n    def test_that_will_run():\n        assert 1\n\n\n.. code-block:: bash\n\n    $ py.test -v test_example.py\n\n    ============================= test session starts ==============================\n    platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6\n    cachedir: .cache\n    rootdir: /tmp/example, inifile:\n    plugins: only-1.0.0\n    collected 2 items\n\n    test_example.py::test_that_will_run PASSED\n\n    =========================== 1 passed in 0.00 seconds ===========================\n\n\nOr use it on classes\n\n.. code-block:: python\n\n    import pytest\n\n    class TestThatWillNotRun:\n        def test_that_will_not_run(self):\n            assert 0\n\n\n    @pytest.mark.only\n    class TestThatWillRun:\n        def test_that_will_run(self):\n            assert 1\n\n\n.. code-block:: bash\n\n    $ py.test -v test_example.py\n\n    ============================= test session starts ==============================\n    platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6\n    cachedir: .cache\n    rootdir: /tmp/example, inifile:\n    plugins: only-1.0.0\n    collected 2 items\n\n    test_example.py::TestThatWillRun::test_that_will_run PASSED\n\n    =========================== 1 passed in 0.00 seconds ===========================\n\n\nOr use it on modules\n\n.. code-block:: python\n\n    # test_example.py\n    import pytest\n\n    pytestmark = pytest.mark.only\n\n    def test_that_will_run():\n        assert 1\n\n\n.. code-block:: python\n\n    # test_example2.py\n    def test_that_will_not_run():\n        assert 0\n\n\n.. code-block:: bash\n\n    $ py.test -v test_example.py test_example2.py\n\n    ============================= test session starts ==============================\n    platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28/bin/python3.6\n    cachedir: .cache\n    rootdir: /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28, inifile:\n    plugins: only-1.0.0\n    collected 2 items\n\n    test_example.py::test_that_will_run PASSED\n\n    =========================== 1 passed in 0.00 seconds ===========================\n\n\n\nDisable for single test run\n---------------------------\n\nTo run all the tests, regardless of whether ``@pytest.mark.only`` is used, pass\nthe ``--no-only`` flag to pytest:\n\n.. code-block:: bash\n\n    $ py.test --no-only\n\n\nIf ``--no-only`` has already been passed (perhaps by way of ``addopts`` in\n*pytest.ini*), use the ``--only`` flag to re-enable it:\n\n.. code-block:: bash\n\n    $ py.test --no-only --only\n\n\nPylint checker\n--------------\n\nIf you use pylint, you can avoid committing stray `only` marks with the bundled plugin. Just enable the pylint checker in your plugins and enable the `unexpected-focused` rule.\n\n.. code-block:: ini\n\n    [MASTER]\n    load-plugins=pytest_only.ext.pylint\n\n    [MESSAGES CONTROL]\n    enable=unexpected-focused\n\n.. code-block:: console\n\n    $ cat test_ninja.py\n    import pytest\n\n    @pytest.mark.only\n    def test_ninja():\n        pass\n\n    $ pylint test_ninja.py\n    ************* Module mymain\n    test_ninja.py:3:0: W1650: Unexpected focused test(s) using pytest.mark.only: def test_ninja (unexpected-focused)\n\n\nDevelopment\n-----------\n\n1. Install the test/dev requirements using `Poetry <https://python-poetry.org/>`_\n\n    .. code-block:: bash\n\n        poetry install\n\n2. Run the tests\n\n    .. code-block:: bash\n\n        py.test\n\n3. Run the tests on all currently-supported platforms\n\n    .. code-block:: bash\n\n        tox\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Use @pytest.mark.only to run a single test",
    "version": "2.1.1",
    "project_urls": {
        "Homepage": "https://github.com/theY4Kman/pytest-only",
        "Repository": "https://github.com/theY4Kman/pytest-only"
    },
    "split_keywords": [
        "pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d306f65a216f192eeeead9ea8ccae8d3fe27df79fa93cf7e28900a0c96d1ca22",
                "md5": "83f0684416b7186e70077f498800841c",
                "sha256": "1bb74ae95ac44366da85ccf7da0815f11ae0bb0d07754d0def7f14584ead5988"
            },
            "downloads": -1,
            "filename": "pytest_only-2.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "83f0684416b7186e70077f498800841c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7.2,<4",
            "size": 6494,
            "upload_time": "2024-03-09T18:01:16",
            "upload_time_iso_8601": "2024-03-09T18:01:16.960087Z",
            "url": "https://files.pythonhosted.org/packages/d3/06/f65a216f192eeeead9ea8ccae8d3fe27df79fa93cf7e28900a0c96d1ca22/pytest_only-2.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "355c8772432474700a9f784776dd22ae471c33f077a06cd56884cd1a176c4d18",
                "md5": "7887512c7fd08e0bf7f0f20cddfb448d",
                "sha256": "d417e8d9f962fc772b7e130ab2319fe056f9191ff555fc178f4b66d6a18e248c"
            },
            "downloads": -1,
            "filename": "pytest_only-2.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7887512c7fd08e0bf7f0f20cddfb448d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7.2,<4",
            "size": 4924,
            "upload_time": "2024-03-09T18:01:18",
            "upload_time_iso_8601": "2024-03-09T18:01:18.621326Z",
            "url": "https://files.pythonhosted.org/packages/35/5c/8772432474700a9f784776dd22ae471c33f077a06cd56884cd1a176c4d18/pytest_only-2.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-09 18:01:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "theY4Kman",
    "github_project": "pytest-only",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "pytest-only"
}
        
Elapsed time: 0.21182s