1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (C) 2024 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import subprocess
17import pkg_resources
18import pytest
19import os
20import time
21
22GetVersion = "V1.0.0"
23
24def check_library_installation(library_name):
25    try:
26        pkg_resources.get_distribution(library_name)
27        return 0
28    except pkg_resources.DistributionNotFound:
29        print(f"\n\n{library_name} is not installed.\n\n")
30        print(f"try to use command below:")
31        print(f"pip install {library_name}")
32        return 1
33
34
35if __name__  == '__main__':
36    if check_library_installation("pytest"):
37        subprocess.check_call(["pip", "install", "-r", "requirements.txt"])
38        if check_library_installation("pytest"):
39            exit(1)
40
41    start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
42    pytest.main()
43    end_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
44    report_time = time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime(time.time()))
45    report_dir = os.path.join(os.getcwd(), "reports")
46    report_file = os.path.join(report_dir, f"{report_time}report.html")
47    print(f"Test over, the script version is {GetVersion},"
48        f" start at {start_time}, end at {end_time} \n"
49        f"=======>{report_file} is saved. \n"
50    )
51    input("=======>press [Enter] key to Show logs.")
52
53
54    # os.system("allure generate temp -o reports")
55