3 Star 3 Fork 2

Gitee 极速下载 / pyops

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/five3/pyops
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

py-ops: 一款面向编程的Python关键字测试框架™

https://raw.githubusercontent.com/five3/pyops/master/images/testqa.png

☤ 说明

这是一款基于``pytest``封装,同时支持``关键字``和``BDD``,测试数据分离,面向编程,轻量级的,对上层自动化应用友好的基础测试框架。

其主要核心功能:

  • 支持关键字定义
  • 支持关键字组装
  • 测试数据透传

该框架的主要特点:

  • 基于``pytest``框架开发,支持原生插件
  • 同时具备``关键字``和``BDD``框架的特点
  • 无二次学习成本(Python|json)
  • 天然支持``测试数据分离``与传递
  • 对上层应用提供友好的封装接口
  • 支持脚本``Debug``调试
  • 代码量少(7个文件500行代码)

☤ 环境安装

pip install py-ops

或者使用下面命令安装最新版:

pip install git+https://github.com/five3/pyops.git

☤ 快速开始

使用该框架非常的方便,基本没有学习成本。安装完成之后,在任意目录执行如下命令创建一个测试项目:

pyops startproject test1

命令执行完成之后,会在当前目录创建一个[test1]目录,具体的目录结构如下:

|- test1
    |-- ah_ext
        |-- __init__.py
    |-- demo.json

接着在测试项目根目录(test1)执行如下命令运行测试:

pyops run

该命令默认会执行当前目录先全部的json用例文件,如果你希望只执行部分的json用例,则可以指定特定的文件名:

pyops run demo.jsom demo2.json

在执行完run命令后会在当前目录生成多个文件,具体的文件如下:

|- test1
    |-- ah_ext
        |-- __init__.py
    |-- demo.json
    |-- demo.py
    |-- pytest.ini
    |-- report.html
    |-- std.log

其中demo.py是由json文件生成的同名用例文件,这个是执行测试流程中的产物,也是执行测试的真正入口点。 report.html是测试报告,std.log则是测试的详细日志,pytest.ini自动生成的pytest配置文件。

如果你希望单独生成一个py用例文件,可以使用下面的命令:

pyops make demo.json

json文件中还可以对case配置disable字段,为true时则不会执行,不填时默认为false。 如果希望强制运行disable为true的用例,可以使用forcerun命令。

pyops forcerun

当然,你也可以通过原生的pytest命令来执行,前提是已经通过make、run命令生成了py文件。比如:

pytest demo.py::test_cls_name::test_case_name -s -v --force_run --pytest_report report.html

其中-s、-v是pytest原生的参数,--force_run是pyops插件参数,--pytest_report则是PyTestReport插件参数。

☤ 框架设计结构

https://raw.githubusercontent.com/five3/pyops/master/images/apic.png

☤ 自动生成用例说明

自动生成的demo.json测试用例内容如下:

{
    "name": "TestDemo",
    "desc": ".....background......",
    "tag": "smoking_test",
    "setup_class": [],
    "teardown_class": [],
    "setup": [],
    "teardown": [],
    "cases": {
        "test_add": {
            "desc": "",
            "tags": [],
            "data": {
                "x": 2,
                "y": 3,
                "expect": 5
            },
            "flow": ["调用add"],
            "check": ["检查add"]
        }
    }
}

自动生成的``ah_ext.__init__.py``文件内容如下:

import logging
from pyops.decorator import (make_check, make_flow, alias)

logger = logging.getLogger()

def add(x, y):
    print('add')
    return x + y

@alias('调用add')
@make_flow
def call_add(data):
    """
        data: 即json配置文件中的case节点下对应data字典对象
    """
    data['actual'] = add(data['x'], data['y'])

@alias('检查add')
@make_check
def check_add(data):
    """
        data: 即json配置文件中的case节点下对应data字典对象
    """
    return data['actual'] == data['expect']
MIT License Copyright (c) 2019 Xiaowu Chen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

这是一款基于pytest封装,同时支持关键字和BDD,测试数据分离,面向编程,轻量级的,对上层自动化应用友好的基础测试框架 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/mirrors/pyops.git
git@gitee.com:mirrors/pyops.git
mirrors
pyops
pyops
master

搜索帮助