一个与pytest一起使用的简单插件

pytest-elk-reporter的Python项目详细描述


Pytest麋鹿报告器

PyPI versionPython versionsSee Build Status on Travis CISee Build Status on AppVeyorLibraries.io dependency status for GitHub repoUsing BlackCodecov Reports

ELK堆栈发送pytest测试结果的插件,带有额外的上下文数据

功能

  • 在测试完成时,将每个测试结果报告到elasticsearch中
  • 自动将上下文数据附加到每个测试:
    • Git信息,如branchlast commit
    • 所有詹金斯环境变量
    • 用户名(如果可用)
  • 使用所有上下文数据向Elastic报告每个会话的测试摘要
  • 可以将任何用户数据附加到发送到Elastic的上下文中

要求

安装

您可以通过PyPI中的pip安装“pytest elk reporter”

pip install pytest-elk-reporter

弹性搜索配置

我们需要为即将使用的索引启用自动创建索引, 由于我们没有创建索引的代码,因此这是默认值

curl -X PUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d'{    "persistent": {        "action.auto_create_index": "true"    }}'

有关此ElasticSearch功能的详细信息,请检查index documention

用法

从命令行运行和配置

pytest --es-address 127.0.0.1:9200
# or if you need user/password to authenticate
pytest --es-address my-elk-server.io:9200 --es-username fruch --es-password 'passwordsarenicetohave'

从代码配置

importpytest@pytest.fixture(scope='session',autouse=True)defconfigure_es(elk_reporter):# TODO: get cerdentials in more secure fashion programtically, maybe AWS secrects or the likes# or put them in plain-text in the code... what can ever go wrong...elk_reporter.es_address="my-elk-server.io:9200"elk_reporter.es_user='fruch'elk_reporter.es_password='passwordsarenicetohave'elk_reporter.es_index_name='test_data'

从pytest ini文件配置

# put this in pytest.ini / tox.ini / setup.cfg[pytest]es_address=my-elk-server.io:9200es_user=fruches_password=passwordsarenicetohavees_index_name=test_data

pytest docs 有关如何使用.ini文件配置的详细信息

为整个会话收集上下文数据

例如,有了它,我将能够为每个版本构建一个仪表板

@pytest.fixture(scope="session",autouse=True)defreport_formal_version_to_elk(request):"""    Append my own data specific, for example which of the code uner test is used    """# TODO: take it programticly of of the code under test...my_data={"formal_version":"1.0.0-rc2"}elk=request.config.pluginmanager.get_plugin("elk-reporter-runtime")elk.session_data.update(**my_data)

收集特定测试的数据

deftest_my_service_and_collect_timings(request,elk_reporter):response=requests.get("http://my-server.io/api/do_something")assertresponse.status_code==200elk_reporter.append_test_data(request,{"do_something_response_time":response.elapsed.total_seconds()})# now doing response time per version dashboard quite easy# and yeah, it's not exactly real usable metric, it's just an example...

贡献

我们非常欢迎您的贡献。测试可以用^{}运行,请确保 在提交请求之前,覆盖范围至少保持不变。

许可证

“pytest elk reporter”是根据MIT许可证的条款发布的免费开源软件

问题

如果您遇到任何问题,请file an issue连同详细说明。

谢谢

这个pytest插件是用Cookiecutter@hackebrotcookiecutter-pytest-plugin模板生成的。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java连接usb到uart设备到安卓设备>3.1   可以强制Php中的web应用程序与Java中的桌面应用程序一起工作吗?   java为什么自定义系统类加载器不工作?   数组在Java中解析具有多个分隔符的字符串   PMD Java 8德米特定律   JavaSpringMVC表单验证不适用于嵌套的复杂类型   让Eclipse Java组织导入以使用Google checkstyle   java Appium:无法创建新会话   java如何在数组中声明新字段   java如何解决“无法初始化类org.apache.cassandra.config.DatabaseDescriptor”?   java AsyncTask创建socket   java向@CreatedBy添加更多信息   如何在ubuntu中运行包含大量jars依赖项的java文件   java如何使用<s:select>标记并在中休眠来填充下拉列表?   java获取错误:找不到符号变量“level”和“next_level_button”   javaweb应用中基于UI的ajax显示代码流   Java长到MySql   java JvisualVM:奇怪的应用程序行为   ubuntu将Java程序的输出结果保存到一个文件中