pytest 发送邮件
时间: 2023-10-24 07:37:15 浏览: 41
你可以使用pytest-email插件来发送测试结果的邮件。以下是一些基本步骤:
1. 安装pytest-email插件:`pip install pytest-email`
2. 在你的pytest配置文件中,添加以下内容:
```python
# content of pytest.ini
[email]
smtp_server = smtp.gmail.com
smtp_port = 465
smtp_ssl = true
smtp_user = your_email@gmail.com
smtp_password = your_email_password
smtp_sender = your_email@gmail.com
smtp_recipients = recipient1@example.com,recipient2@example.com
```
注意替换`smtp_server`,`smtp_user`,`smtp_password`,`smtp_sender`和`smtp_recipients`为你自己的值。
3. 运行pytest命令时,添加`--email`选项。例如:
```
pytest --email
```
这将运行测试并发送邮件。
你还可以使用`--email-body`和`--email-subject`选项来自定义邮件正文和主题,例如:
```
pytest --email --email-body="这是测试结果邮件" --email-subject="测试结果"
```
更多详细信息,请参考pytest-email文档:https://pypi.org/project/pytest-email/