一个与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 Selenium Web驱动程序。负载策略不稳定   JAVAsql。SQLException:没有合适的驱动程序无法创建“oracle”类的JDBC驱动程序。jdbc。驾驶员用于连接URL的OracleDriver   java谷歌地图“优化路径点”如何解决旅行推销员的问题?   java这段代码可能会造成潜在的内存泄漏吗?   java更改JCombobox的高度   java如何清除jtable中的数据   JavaHadoop:错误安全性。UserGroupInformation:MapReduce程序中的PriviledgedActionException   java如何将sonarlint添加到gradle任务中?   性能为什么Java排序优于原语计数排序   java Spring属性PlaceHolderConfigure从数据库加载   java从泛型获取类不起作用   java Spring@Transactional传播属性   java试图拥有主菜单和子菜单类   XSL的java后处理步骤   java第一个字母和最后一个字母、第二个字母和倒数第二个字母之间的差值之和,依此类推,直到单词的中心   switch语句在Java中的下一个出发点   java 安卓如何在OnBackpress()时设置viewpager的特定项目位置?