pytest-send-email


Namepytest-send-email JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/hanzhichao/pytest-send-email
SummarySend pytest execution result email
upload_time2024-09-02 02:51:41
maintainerNone
docs_urlNone
authorHan Zhichao
requires_pythonNone
licenseMIT license
keywords pytest py.test email smtp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-send-email

[![PyPI version](https://badge.fury.io/py/pytest-send-email.svg)](https://badge.fury.io/py/pytest-send-email)
[![Downloads](https://pepy.tech/badge/pytest-send-email)](https://pepy.tech/project/pytest-send-email)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)]()
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)]()
[![Open Source Love png1](https://badges.frapsoft.com/os/v1/open-source.png?v=103)]()


Pytest发送Email邮件插件

---

### 特性

- SMTP服务器及用户密码信息支持写到环境变量或pytest.ini中,也可以命令行参数传入
- 支持选择使用SMTP或SMTP_SSL,支持自定义SMTP端口
- 支持在pytest.ini或命令行参数中定制邮件主题,邮件正文,邮件正文HTML模板
- 支持添加多个附件,文件路径以逗号隔开
- 支持多个收件人,文件路径以逗号隔开

---

### 如何使用

1. 安装 `pytest-send-email`

使用pip安装
```sh
pip pytest-send-email
```

2. 使用方法
在环境变量中添加SMTP_HOST, SMTP_USER,SMTP_PWD并source
```sh
export SMTP_HOST=<smtp-server>
export SMTP_USER=<your-email-user>
export SMTP_PWD=<your-password or token>
```

使用以下参数运行pytest
```sh
pytest --send-email --email-receivers=abc@gmail.com,abc@hotmail.com
```

> 也可以将参数配置到pytest.ini中
```ini
[pytest]
addopts = --send-email --html=report.html

smtp_host = <smtp-server>
smtp_port = <smtp-port>
smtp_user = <your-email-user>
smtp_pwd = <your-password or token>
smtp_ssl = False


email_receivers = superhin@126.com
email_subject = Pytest Test Report
email_body = 
    Hi, this is the test report
email_attachments=test_a.py,report.html

```
或在配置在pytest.ini`[email]`段中
```ini
[pytest] 
addopts = --send-email --html=report.html

[email]
host = <smtp-server>
port = <smtp-port>
user = <your-email-user>
password = <your-password or token>
ssl = False

receivers = superhin@126.com
subject = Pytest Test Report
body = 
    Hi, this is the test report
attachments=test_a.py,report.html
```

然后运行pytest命令即可

3. 支持的命令行参数

- --send-email: 是否发送邮件
- --email-receivers: 邮件收件人,逗号分隔
- --smtp-host: SMTP服务器地址
- --smtp-port: SMTP端口号
- --smtp-user: 邮箱用户
- --smtp-pwd: 邮箱密码
- --smtp-ssl: 是否使用SMTP_SSL
- --email-subject: 邮件主题
- --email-body: 邮件内容,支持HTML
- --email-template: 邮件模板文件路径
- --email-attachments: 邮件附件,逗号分隔

4. 支持的pytest.ini选项

- --smtp_host: SMTP服务器地址
- --smtp_port: SMTP端口号
- --smtp_user: 邮箱用户
- --smtp_pwd: 邮箱密码
- --smtp_ssl: 是否使用SMTP_SSL
- --email_subject: 邮件主题
- --email_body: 邮件内容,支持HTML
- --email_receivers: Email receivers, comma-separated
- --email_template: 邮件模板文件路径
- --email_attachments: 邮件附件,逗号分隔

> 如果你想发邮件,最少要配置--send-email和--email-receivers或email_receivers
---

*报告示例*

<img src="pytest_email.png" alt="pytest_email.png">

---

### 报告信息

- Total: 用例总数
- Passed:成功用例总数
- Failed:失败用例总数
- Skipped:跳过用例总数
- Error:出错用例总数
- XPassed:非期望成功用例总数
- XFailed:期望失败总数

### Todo
- 增加执行时间,时长,用例失败信息,日志,图表等更多的信息
- 支持JinJa2渲染模板
- 支持对用例标记失败时发邮件给谁

---

- Email: <a href="mailto:superhin@126.com?Subject=Pytest%20Email" target="_blank">`superhin@126.com`</a> 
- Blog: <a href="https://www.cnblogs.com/superhin/" target="_blank">`博客园 韩志超`</a>
- 简书: <a href="https://www.jianshu.com/u/0115903ded22" target="_blank">`简书 韩志超`</a>


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hanzhichao/pytest-send-email",
    "name": "pytest-send-email",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "pytest, py.test, email, smtp",
    "author": "Han Zhichao",
    "author_email": "superhin@126.com",
    "download_url": "https://files.pythonhosted.org/packages/15/fe/3654e7e1b86a378756537f8b100d5390939ba8e36a535a3f972b4de606d9/pytest_send_email-0.1.1.tar.gz",
    "platform": null,
    "description": "# pytest-send-email\n\n[![PyPI version](https://badge.fury.io/py/pytest-send-email.svg)](https://badge.fury.io/py/pytest-send-email)\n[![Downloads](https://pepy.tech/badge/pytest-send-email)](https://pepy.tech/project/pytest-send-email)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)]()\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)]()\n[![Open Source Love png1](https://badges.frapsoft.com/os/v1/open-source.png?v=103)]()\n\n\nPytest\u53d1\u9001Email\u90ae\u4ef6\u63d2\u4ef6\n\n---\n\n### \u7279\u6027\n\n- SMTP\u670d\u52a1\u5668\u53ca\u7528\u6237\u5bc6\u7801\u4fe1\u606f\u652f\u6301\u5199\u5230\u73af\u5883\u53d8\u91cf\u6216pytest.ini\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u547d\u4ee4\u884c\u53c2\u6570\u4f20\u5165\n- \u652f\u6301\u9009\u62e9\u4f7f\u7528SMTP\u6216SMTP_SSL\uff0c\u652f\u6301\u81ea\u5b9a\u4e49SMTP\u7aef\u53e3\n- \u652f\u6301\u5728pytest.ini\u6216\u547d\u4ee4\u884c\u53c2\u6570\u4e2d\u5b9a\u5236\u90ae\u4ef6\u4e3b\u9898\uff0c\u90ae\u4ef6\u6b63\u6587\uff0c\u90ae\u4ef6\u6b63\u6587HTML\u6a21\u677f\n- \u652f\u6301\u6dfb\u52a0\u591a\u4e2a\u9644\u4ef6\uff0c\u6587\u4ef6\u8def\u5f84\u4ee5\u9017\u53f7\u9694\u5f00\n- \u652f\u6301\u591a\u4e2a\u6536\u4ef6\u4eba\uff0c\u6587\u4ef6\u8def\u5f84\u4ee5\u9017\u53f7\u9694\u5f00\n\n---\n\n### \u5982\u4f55\u4f7f\u7528\n\n1. \u5b89\u88c5 `pytest-send-email`\n\n\u4f7f\u7528pip\u5b89\u88c5\n```sh\npip pytest-send-email\n```\n\n2. \u4f7f\u7528\u65b9\u6cd5\n\u5728\u73af\u5883\u53d8\u91cf\u4e2d\u6dfb\u52a0SMTP_HOST, SMTP_USER,SMTP_PWD\u5e76source\n```sh\nexport SMTP_HOST=<smtp-server>\nexport SMTP_USER=<your-email-user>\nexport SMTP_PWD=<your-password or token>\n```\n\n\u4f7f\u7528\u4ee5\u4e0b\u53c2\u6570\u8fd0\u884cpytest\n```sh\npytest --send-email --email-receivers=abc@gmail.com,abc@hotmail.com\n```\n\n> \u4e5f\u53ef\u4ee5\u5c06\u53c2\u6570\u914d\u7f6e\u5230pytest.ini\u4e2d\n```ini\n[pytest]\naddopts = --send-email --html=report.html\n\nsmtp_host = <smtp-server>\nsmtp_port = <smtp-port>\nsmtp_user = <your-email-user>\nsmtp_pwd = <your-password or token>\nsmtp_ssl = False\n\n\nemail_receivers = superhin@126.com\nemail_subject = Pytest Test Report\nemail_body = \n    Hi, this is the test report\nemail_attachments=test_a.py,report.html\n\n```\n\u6216\u5728\u914d\u7f6e\u5728pytest.ini`[email]`\u6bb5\u4e2d\n```ini\n[pytest] \naddopts = --send-email --html=report.html\n\n[email]\nhost = <smtp-server>\nport = <smtp-port>\nuser = <your-email-user>\npassword = <your-password or token>\nssl = False\n\nreceivers = superhin@126.com\nsubject = Pytest Test Report\nbody = \n    Hi, this is the test report\nattachments=test_a.py,report.html\n```\n\n\u7136\u540e\u8fd0\u884cpytest\u547d\u4ee4\u5373\u53ef\n\n3. \u652f\u6301\u7684\u547d\u4ee4\u884c\u53c2\u6570\n\n- --send-email: \u662f\u5426\u53d1\u9001\u90ae\u4ef6\n- --email-receivers: \u90ae\u4ef6\u6536\u4ef6\u4eba\uff0c\u9017\u53f7\u5206\u9694\n- --smtp-host: SMTP\u670d\u52a1\u5668\u5730\u5740\n- --smtp-port: SMTP\u7aef\u53e3\u53f7\n- --smtp-user: \u90ae\u7bb1\u7528\u6237\n- --smtp-pwd: \u90ae\u7bb1\u5bc6\u7801\n- --smtp-ssl: \u662f\u5426\u4f7f\u7528SMTP_SSL\n- --email-subject: \u90ae\u4ef6\u4e3b\u9898\n- --email-body: \u90ae\u4ef6\u5185\u5bb9\uff0c\u652f\u6301HTML\n- --email-template: \u90ae\u4ef6\u6a21\u677f\u6587\u4ef6\u8def\u5f84\n- --email-attachments: \u90ae\u4ef6\u9644\u4ef6\uff0c\u9017\u53f7\u5206\u9694\n\n4. \u652f\u6301\u7684pytest.ini\u9009\u9879\n\n- --smtp_host: SMTP\u670d\u52a1\u5668\u5730\u5740\n- --smtp_port: SMTP\u7aef\u53e3\u53f7\n- --smtp_user: \u90ae\u7bb1\u7528\u6237\n- --smtp_pwd: \u90ae\u7bb1\u5bc6\u7801\n- --smtp_ssl: \u662f\u5426\u4f7f\u7528SMTP_SSL\n- --email_subject: \u90ae\u4ef6\u4e3b\u9898\n- --email_body: \u90ae\u4ef6\u5185\u5bb9\uff0c\u652f\u6301HTML\n- --email_receivers: Email receivers, comma-separated\n- --email_template: \u90ae\u4ef6\u6a21\u677f\u6587\u4ef6\u8def\u5f84\n- --email_attachments: \u90ae\u4ef6\u9644\u4ef6\uff0c\u9017\u53f7\u5206\u9694\n\n> \u5982\u679c\u4f60\u60f3\u53d1\u90ae\u4ef6\uff0c\u6700\u5c11\u8981\u914d\u7f6e--send-email\u548c--email-receivers\u6216email_receivers\n---\n\n*\u62a5\u544a\u793a\u4f8b*\n\n<img src=\"pytest_email.png\" alt=\"pytest_email.png\">\n\n---\n\n### \u62a5\u544a\u4fe1\u606f\n\n- Total: \u7528\u4f8b\u603b\u6570\n- Passed\uff1a\u6210\u529f\u7528\u4f8b\u603b\u6570\n- Failed\uff1a\u5931\u8d25\u7528\u4f8b\u603b\u6570\n- Skipped\uff1a\u8df3\u8fc7\u7528\u4f8b\u603b\u6570\n- Error\uff1a\u51fa\u9519\u7528\u4f8b\u603b\u6570\n- XPassed\uff1a\u975e\u671f\u671b\u6210\u529f\u7528\u4f8b\u603b\u6570\n- XFailed\uff1a\u671f\u671b\u5931\u8d25\u603b\u6570\n\n### Todo\n- \u589e\u52a0\u6267\u884c\u65f6\u95f4\uff0c\u65f6\u957f\uff0c\u7528\u4f8b\u5931\u8d25\u4fe1\u606f\uff0c\u65e5\u5fd7\uff0c\u56fe\u8868\u7b49\u66f4\u591a\u7684\u4fe1\u606f\n- \u652f\u6301JinJa2\u6e32\u67d3\u6a21\u677f\n- \u652f\u6301\u5bf9\u7528\u4f8b\u6807\u8bb0\u5931\u8d25\u65f6\u53d1\u90ae\u4ef6\u7ed9\u8c01\n\n---\n\n- Email: <a href=\"mailto:superhin@126.com?Subject=Pytest%20Email\" target=\"_blank\">`superhin@126.com`</a> \n- Blog: <a href=\"https://www.cnblogs.com/superhin/\" target=\"_blank\">`\u535a\u5ba2\u56ed \u97e9\u5fd7\u8d85`</a>\n- \u7b80\u4e66: <a href=\"https://www.jianshu.com/u/0115903ded22\" target=\"_blank\">`\u7b80\u4e66 \u97e9\u5fd7\u8d85`</a>\n\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Send pytest execution result email",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/hanzhichao/pytest-send-email"
    },
    "split_keywords": [
        "pytest",
        " py.test",
        " email",
        " smtp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "15fe3654e7e1b86a378756537f8b100d5390939ba8e36a535a3f972b4de606d9",
                "md5": "eafa350307f08c6a9117390e07e3c3b9",
                "sha256": "271649e141bd03deb1371dcdfaa2543a7e3f4bcd9917696bbf33fc4b495db006"
            },
            "downloads": -1,
            "filename": "pytest_send_email-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "eafa350307f08c6a9117390e07e3c3b9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7019,
            "upload_time": "2024-09-02T02:51:41",
            "upload_time_iso_8601": "2024-09-02T02:51:41.294773Z",
            "url": "https://files.pythonhosted.org/packages/15/fe/3654e7e1b86a378756537f8b100d5390939ba8e36a535a3f972b4de606d9/pytest_send_email-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-02 02:51:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hanzhichao",
    "github_project": "pytest-send-email",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pytest-send-email"
}
        
Elapsed time: 0.31254s