-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
30 lines (24 loc) · 830 Bytes
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import smtplib
import ssl
from email.message import EmailMessage
from dotenv import load_dotenv
def pytest_sessionfinish(session, exitstatus):
"""
Called after whole test run finished, right before
returning the exit status to the system.
"""
if exitstatus == 0:
return
load_dotenv()
port = 465 # For SSL
smtp_server = "smtp.gmail.com"
sender_email = os.getenv("FROM_EMAIL")
email_message = EmailMessage()
email_message["Subject"] = str(session)
email_message["To"] = os.getenv("TO_EMAIL")
email_message.set_content(str(session.items))
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, os.getenv("PASSWORD"))
server.send_message(email_message)