# This is a sample Python script.
import os

import pytest


# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


def create_report_dir():
    # 创建测试报告目录，此时目录结构不要随便更改，函数也不要随便移动，因为直接与路径挂钩
    # 直接拼接目录
    abs_path = os.path.abspath(__file__)
    # 往上一级到项目目录
    project_dir = os.path.dirname(abs_path)
    # 开始拼接报告目录
    log_dir = os.path.join(project_dir, 'report')
    # 若该目录不存在则创建该目录
    if not os.path.exists(log_dir):
        os.mkdir(log_dir)
    return log_dir


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')
    # pytest.main(
    #    ['-vs', 'D:/pythonProject/atuobase/test_login/test_login_success.py', '--reruns', '3', '--reruns-delay', '2', '--alluredir',
    #     os.path.join(os.sep, 'autotest_sc_report'),
    #     '--clean-alluredir'])

    # 创建报告目录
    report_dir = create_report_dir()
    pytest.main(
        ['-vs', 'D:/pythonProject/atuobase/test_login/test_login_success.py', '--reruns', '3', '--reruns-delay', '2', '--alluredir',
         report_dir, '--clean-alluredir'])
    # 开始执行用例
    #pytest.main(
    #    ['-vs', 'D:/pythonProject/atuobase/test_login', '--reruns', '3', '--reruns-delay', '2', '--alluredir',
    #     report_dir, '--clean-alluredir'])
    # Mail().send()
    os.system('allure serve %s' % report_dir)

    # 可以在终端执行命令 pytest D:\pythonProject\atuobase\test_login\test_login_success.py
