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 22GET_VERSION = "V1.0.0" 23 24 25def check_library_installation(library_name): 26 try: 27 pkg_resources.get_distribution(library_name) 28 return 0 29 except pkg_resources.DistributionNotFound: 30 print(f"\n\n{library_name} is not installed.\n\n") 31 print(f"try to use command below:") 32 print(f"pip install {library_name}") 33 return 1 34 35 36if __name__ == '__main__': 37 if check_library_installation("pytest"): 38 subprocess.check_call(["pip", "install", "-r", "requirements.txt"]) 39 if check_library_installation("pytest"): 40 exit(1) 41 42 start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) 43 pytest.main() 44 end_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) 45 report_time = time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime(time.time())) 46 report_dir = os.path.join(os.getcwd(), "reports") 47 report_file = os.path.join(report_dir, f"{report_time}report.html") 48 print(f"Test over, the script version is {GET_VERSION}," 49 f" start at {start_time}, end at {end_time} \n" 50 f"=======>{report_file} is saved. \n" 51 ) 52 input("=======>press [Enter] key to Show logs.") 53