# 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, 'results')
    # 若该目录不存在则创建该目录
    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/operator_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/operator_login/test_login_success.py', '--reruns', '3', '--reruns-delay', '2', '--alluredir',
    #     report_dir, '--clean-alluredir'])
    # 开始执行用例
    # pytest.main(
    #    ['-vs', 'D:/pythonProject/atuobase/operator_login', 'D:/pythonProject/atuobase/buy/test_buy_one_nonseq_commodity.py::TestBuyOneNonseqCommodity::test_buy_one_nonseq_commodity', '--reruns', '3', '--reruns-delay', '2', '--alluredir',
    #     report_dir, '--clean-alluredir'])
    # Mail().send()
    #pytest.main(
    #    ['-vs',  '../autotest-airtest-web-sc/buy','../autotest-airtest-web-sc/operator_login', '--reruns', '3', '--reruns-delay', '2', '--alluredir',
    #     report_dir, '--clean-alluredir'])
    pytest.main(
        ['-vs',  '../autotest-airtest-web-sc/operator_login', '--reruns', '3', '--reruns-delay', '2', '--alluredir',
         report_dir, '--clean-alluredir'])
    os.system('allure generate -c results/ -o report/')
    #os.system('allure serve %s' % report_dir)

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