pytest-only


Namepytest-only JSON
Version 2.1.2 PyPI version JSON
download
home_pagehttps://github.com/theY4Kman/pytest-only
SummaryUse @pytest.mark.only to run a single test
upload_time2024-05-27 17:04:18
maintainerNone
docs_urlNone
authorZach Kanzler
requires_python<4.0,>=3.8
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": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "pytest",
    "author": "Zach Kanzler",
    "author_email": "they4kman@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/1f/2f/937d554943477a540aa2aae2b4c47ad41c2f089f47691288938c67e94143/pytest_only-2.1.2.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.2",
    "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": "da953cf1a035048ee224a5dc701a3f41a5ec8684b030d217517bdf7da2f545aa",
                "md5": "cea9f79a414a4d5b3e5a25d85b494a36",
                "sha256": "04dffe2aed64a741145ce5ad25b5df3ae4212e01ff885a8821fd2318eb509e91"
            },
            "downloads": -1,
            "filename": "pytest_only-2.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cea9f79a414a4d5b3e5a25d85b494a36",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 6456,
            "upload_time": "2024-05-27T17:04:16",
            "upload_time_iso_8601": "2024-05-27T17:04:16.936143Z",
            "url": "https://files.pythonhosted.org/packages/da/95/3cf1a035048ee224a5dc701a3f41a5ec8684b030d217517bdf7da2f545aa/pytest_only-2.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1f2f937d554943477a540aa2aae2b4c47ad41c2f089f47691288938c67e94143",
                "md5": "de05d91bc611d078856e610a9c9ee53d",
                "sha256": "e341acc083e3bb66debc660b7d5d71ae3b31da5edc2a737280d7304221ab0c29"
            },
            "downloads": -1,
            "filename": "pytest_only-2.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "de05d91bc611d078856e610a9c9ee53d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 4863,
            "upload_time": "2024-05-27T17:04:18",
            "upload_time_iso_8601": "2024-05-27T17:04:18.626770Z",
            "url": "https://files.pythonhosted.org/packages/1f/2f/937d554943477a540aa2aae2b4c47ad41c2f089f47691288938c67e94143/pytest_only-2.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-27 17:04: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: 1.04200s