pytest-runtime-yoyo


Namepytest-runtime-yoyo JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://gitee.com/yoyoketang/pytest-runtime-yoyo
Summaryrun case mark timeout
upload_time2023-06-12 07:23:17
maintainer
docs_urlNone
author上海-悠悠
requires_python>=3.8
licenseproprietary
keywords pytest py.test pytest-runtime pytest-runtime-yoyo
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pypi_seed
=========

pytest 执行用例的时候,我们希望对用例的运行时间断言,当用例执行时长大于预期标记此用例失败。
`runtime(1)` 运行时长单位是秒

基本示例 test_demo.py

::

    import pytest
    import time


    def test_a1():
        time.sleep(2)


    @pytest.mark.runtime(1)
    def test_a2():
        time.sleep(2)


运行结果

::

    ======================== short test summary info =====================
    FAILED test_demo.py::test_a2
    ======================== 1 failed, 1 passed in 4.18s ===============



联系我们
--------------------------

作者-上海悠悠 微信/QQ交流:283340479
blog地址 https://www.cnblogs.com/yoyoketang/


版本变更记录
--------------------------

v1.0.0 发布时间: 2023/6/12

实现功能

- 1.用例中使用 `@pytest.mark.runtime(1)` 标记用例执行时间
- 2.pytest.ini 新增 `runtime` 全局参数
- 3.命令行中新增 `--runtime` 全局参数




Installation / 安装
--------------------------
最近环境体验

- Python 3.8+ 版本
- Pytest 7.2.0+ 新版

pip 安装插件

::

    pip install pytest-runtime-yoyo



Usage / 标记用例运行时长
--------------------------

基于函数的用例中使用 `@pytest.mark.runtime(1)` 标记用例执行时间

::

    import pytest
    import time


    def test_a1():
        time.sleep(2)


    @pytest.mark.runtime(1)
    def test_a2():
        time.sleep(2)


基于测试类的用例, 在测试类上标记runtime,对测试类下的每个用例都会生效

::

    import pytest
    import time


    @pytest.mark.runtime(3)
    class TestRun:

        def test_a3(self):
            time.sleep(2)

        def test_a4(self):
            time.sleep(1)




标记模块下全部用例
--------------------------

对整个测试模块下的用例全部标记 runtime

::

    import pytest
    import time

    pytestmark = pytest.mark.runtime(3)


    def test_a5():
        time.sleep(1)


    def test_a6():
        time.sleep(2)


    class TestRun:

        def test_a7(self):
            time.sleep(2)

        def test_a8(self):
            time.sleep(4)

执行结果

::

    collected 4 items
    test_x2.py ...F                                                                                                   [100%]

    ================ FAILURES ===================================
    _____________________ TestRun.test_a8 __________________________
    ================= short test summary info =====================
    FAILED test_x2.py::TestRun::test_a8
    ================= 1 failed, 3 passed in 9.15s =======


如果测试模块,测试类和测试用例上都有runtime 标记

::

    import pytest
    import time

    pytestmark = pytest.mark.runtime(3)


    def test_a5():
        time.sleep(1)


    def test_a6():
        time.sleep(2)


    @pytest.mark.runtime(1)
    class TestRun:

        def test_a7(self):
            time.sleep(2)

        @pytest.mark.runtime(5)
        def test_a8(self):
            time.sleep(4)


那么运行的优先级是: 测试用例 runtime > 测试类 runtime > 测试模块 runtime


全局用例配置
--------------------------

对全部用例设置 runtime 标记,可以在 `pytest.ini` 中设置全局配置

::

    [pytest]

    runtime = 3

也可以在执行 pytest 命令的时候带上命令行参数`--runtime`

::

    pytest --runtime=3


优先级是: 命令行参数 > pytest.ini 配置
全局配置只针对测试模块,测试类,测试用例没标记 runtime 的用例生效。
如果测试模块,测试类,测试用例有标记 runtime,那么优先级是大于全局配置的。

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitee.com/yoyoketang/pytest-runtime-yoyo",
    "name": "pytest-runtime-yoyo",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "pytest,py.test,pytest-runtime,pytest-runtime-yoyo",
    "author": "\u4e0a\u6d77-\u60a0\u60a0",
    "author_email": "283340479@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/e4/c3/637a0210a7cd7f9b134ea718314470058b51ec9fa6e82bc3507161b8b5a2/pytest-runtime-yoyo-1.0.1.tar.gz",
    "platform": null,
    "description": "pypi_seed\r\n=========\r\n\r\npytest \u6267\u884c\u7528\u4f8b\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5e0c\u671b\u5bf9\u7528\u4f8b\u7684\u8fd0\u884c\u65f6\u95f4\u65ad\u8a00\uff0c\u5f53\u7528\u4f8b\u6267\u884c\u65f6\u957f\u5927\u4e8e\u9884\u671f\u6807\u8bb0\u6b64\u7528\u4f8b\u5931\u8d25\u3002\r\n`runtime(1)` \u8fd0\u884c\u65f6\u957f\u5355\u4f4d\u662f\u79d2\r\n\r\n\u57fa\u672c\u793a\u4f8b test_demo.py\r\n\r\n::\r\n\r\n    import pytest\r\n    import time\r\n\r\n\r\n    def test_a1():\r\n        time.sleep(2)\r\n\r\n\r\n    @pytest.mark.runtime(1)\r\n    def test_a2():\r\n        time.sleep(2)\r\n\r\n\r\n\u8fd0\u884c\u7ed3\u679c\r\n\r\n::\r\n\r\n    ======================== short test summary info =====================\r\n    FAILED test_demo.py::test_a2\r\n    ======================== 1 failed, 1 passed in 4.18s ===============\r\n\r\n\r\n\r\n\u8054\u7cfb\u6211\u4eec\r\n--------------------------\r\n\r\n\u4f5c\u8005-\u4e0a\u6d77\u60a0\u60a0 \u5fae\u4fe1/QQ\u4ea4\u6d41:283340479\r\nblog\u5730\u5740 https://www.cnblogs.com/yoyoketang/\r\n\r\n\r\n\u7248\u672c\u53d8\u66f4\u8bb0\u5f55\r\n--------------------------\r\n\r\nv1.0.0 \u53d1\u5e03\u65f6\u95f4: 2023/6/12\r\n\r\n\u5b9e\u73b0\u529f\u80fd\r\n\r\n- 1.\u7528\u4f8b\u4e2d\u4f7f\u7528 `@pytest.mark.runtime(1)` \u6807\u8bb0\u7528\u4f8b\u6267\u884c\u65f6\u95f4\r\n- 2.pytest.ini \u65b0\u589e `runtime` \u5168\u5c40\u53c2\u6570\r\n- 3.\u547d\u4ee4\u884c\u4e2d\u65b0\u589e `--runtime` \u5168\u5c40\u53c2\u6570\r\n\r\n\r\n\r\n\r\nInstallation / \u5b89\u88c5\r\n--------------------------\r\n\u6700\u8fd1\u73af\u5883\u4f53\u9a8c\r\n\r\n- Python 3.8+ \u7248\u672c\r\n- Pytest 7.2.0+ \u65b0\u7248\r\n\r\npip \u5b89\u88c5\u63d2\u4ef6\r\n\r\n::\r\n\r\n    pip install pytest-runtime-yoyo\r\n\r\n\r\n\r\nUsage / \u6807\u8bb0\u7528\u4f8b\u8fd0\u884c\u65f6\u957f\r\n--------------------------\r\n\r\n\u57fa\u4e8e\u51fd\u6570\u7684\u7528\u4f8b\u4e2d\u4f7f\u7528 `@pytest.mark.runtime(1)` \u6807\u8bb0\u7528\u4f8b\u6267\u884c\u65f6\u95f4\r\n\r\n::\r\n\r\n    import pytest\r\n    import time\r\n\r\n\r\n    def test_a1():\r\n        time.sleep(2)\r\n\r\n\r\n    @pytest.mark.runtime(1)\r\n    def test_a2():\r\n        time.sleep(2)\r\n\r\n\r\n\u57fa\u4e8e\u6d4b\u8bd5\u7c7b\u7684\u7528\u4f8b, \u5728\u6d4b\u8bd5\u7c7b\u4e0a\u6807\u8bb0runtime\uff0c\u5bf9\u6d4b\u8bd5\u7c7b\u4e0b\u7684\u6bcf\u4e2a\u7528\u4f8b\u90fd\u4f1a\u751f\u6548\r\n\r\n::\r\n\r\n    import pytest\r\n    import time\r\n\r\n\r\n    @pytest.mark.runtime(3)\r\n    class TestRun:\r\n\r\n        def test_a3(self):\r\n            time.sleep(2)\r\n\r\n        def test_a4(self):\r\n            time.sleep(1)\r\n\r\n\r\n\r\n\r\n\u6807\u8bb0\u6a21\u5757\u4e0b\u5168\u90e8\u7528\u4f8b\r\n--------------------------\r\n\r\n\u5bf9\u6574\u4e2a\u6d4b\u8bd5\u6a21\u5757\u4e0b\u7684\u7528\u4f8b\u5168\u90e8\u6807\u8bb0 runtime\r\n\r\n::\r\n\r\n    import pytest\r\n    import time\r\n\r\n    pytestmark = pytest.mark.runtime(3)\r\n\r\n\r\n    def test_a5():\r\n        time.sleep(1)\r\n\r\n\r\n    def test_a6():\r\n        time.sleep(2)\r\n\r\n\r\n    class TestRun:\r\n\r\n        def test_a7(self):\r\n            time.sleep(2)\r\n\r\n        def test_a8(self):\r\n            time.sleep(4)\r\n\r\n\u6267\u884c\u7ed3\u679c\r\n\r\n::\r\n\r\n    collected 4 items\r\n    test_x2.py ...F                                                                                                   [100%]\r\n\r\n    ================ FAILURES ===================================\r\n    _____________________ TestRun.test_a8 __________________________\r\n    ================= short test summary info =====================\r\n    FAILED test_x2.py::TestRun::test_a8\r\n    ================= 1 failed, 3 passed in 9.15s =======\r\n\r\n\r\n\u5982\u679c\u6d4b\u8bd5\u6a21\u5757\uff0c\u6d4b\u8bd5\u7c7b\u548c\u6d4b\u8bd5\u7528\u4f8b\u4e0a\u90fd\u6709runtime \u6807\u8bb0\r\n\r\n::\r\n\r\n    import pytest\r\n    import time\r\n\r\n    pytestmark = pytest.mark.runtime(3)\r\n\r\n\r\n    def test_a5():\r\n        time.sleep(1)\r\n\r\n\r\n    def test_a6():\r\n        time.sleep(2)\r\n\r\n\r\n    @pytest.mark.runtime(1)\r\n    class TestRun:\r\n\r\n        def test_a7(self):\r\n            time.sleep(2)\r\n\r\n        @pytest.mark.runtime(5)\r\n        def test_a8(self):\r\n            time.sleep(4)\r\n\r\n\r\n\u90a3\u4e48\u8fd0\u884c\u7684\u4f18\u5148\u7ea7\u662f: \u6d4b\u8bd5\u7528\u4f8b runtime > \u6d4b\u8bd5\u7c7b runtime > \u6d4b\u8bd5\u6a21\u5757 runtime\r\n\r\n\r\n\u5168\u5c40\u7528\u4f8b\u914d\u7f6e\r\n--------------------------\r\n\r\n\u5bf9\u5168\u90e8\u7528\u4f8b\u8bbe\u7f6e runtime \u6807\u8bb0\uff0c\u53ef\u4ee5\u5728 `pytest.ini` \u4e2d\u8bbe\u7f6e\u5168\u5c40\u914d\u7f6e\r\n\r\n::\r\n\r\n    [pytest]\r\n\r\n    runtime = 3\r\n\r\n\u4e5f\u53ef\u4ee5\u5728\u6267\u884c pytest \u547d\u4ee4\u7684\u65f6\u5019\u5e26\u4e0a\u547d\u4ee4\u884c\u53c2\u6570`--runtime`\r\n\r\n::\r\n\r\n    pytest --runtime=3\r\n\r\n\r\n\u4f18\u5148\u7ea7\u662f: \u547d\u4ee4\u884c\u53c2\u6570 > pytest.ini \u914d\u7f6e\r\n\u5168\u5c40\u914d\u7f6e\u53ea\u9488\u5bf9\u6d4b\u8bd5\u6a21\u5757\uff0c\u6d4b\u8bd5\u7c7b\uff0c\u6d4b\u8bd5\u7528\u4f8b\u6ca1\u6807\u8bb0 runtime \u7684\u7528\u4f8b\u751f\u6548\u3002\r\n\u5982\u679c\u6d4b\u8bd5\u6a21\u5757\uff0c\u6d4b\u8bd5\u7c7b\uff0c\u6d4b\u8bd5\u7528\u4f8b\u6709\u6807\u8bb0 runtime\uff0c\u90a3\u4e48\u4f18\u5148\u7ea7\u662f\u5927\u4e8e\u5168\u5c40\u914d\u7f6e\u7684\u3002\r\n",
    "bugtrack_url": null,
    "license": "proprietary",
    "summary": "run case mark timeout",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://gitee.com/yoyoketang/pytest-runtime-yoyo"
    },
    "split_keywords": [
        "pytest",
        "py.test",
        "pytest-runtime",
        "pytest-runtime-yoyo"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9379cdbb649a8bb69399c5959029c04f94ae90509ef813c50d64b6b93eda9086",
                "md5": "f5cb9d33dfa5bba7ec2a9b961e2b09b2",
                "sha256": "a3dd0b08563d968a2ee46f8f5989946c0e93bb1ee34a7cc978ad47185f8039e1"
            },
            "downloads": -1,
            "filename": "pytest_runtime_yoyo-1.0.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f5cb9d33dfa5bba7ec2a9b961e2b09b2",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 3765,
            "upload_time": "2023-06-12T07:23:16",
            "upload_time_iso_8601": "2023-06-12T07:23:16.318034Z",
            "url": "https://files.pythonhosted.org/packages/93/79/cdbb649a8bb69399c5959029c04f94ae90509ef813c50d64b6b93eda9086/pytest_runtime_yoyo-1.0.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e4c3637a0210a7cd7f9b134ea718314470058b51ec9fa6e82bc3507161b8b5a2",
                "md5": "b06d68f29da46daf88c75e7d90e46199",
                "sha256": "c9613fca6be4c5ac7ab9bf37d43d8914f3b4d6b4ff2c000c1b41c84cc42bfe66"
            },
            "downloads": -1,
            "filename": "pytest-runtime-yoyo-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b06d68f29da46daf88c75e7d90e46199",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3392,
            "upload_time": "2023-06-12T07:23:17",
            "upload_time_iso_8601": "2023-06-12T07:23:17.668607Z",
            "url": "https://files.pythonhosted.org/packages/e4/c3/637a0210a7cd7f9b134ea718314470058b51ec9fa6e82bc3507161b8b5a2/pytest-runtime-yoyo-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-12 07:23:17",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pytest-runtime-yoyo"
}
        
Elapsed time: 0.07681s