import subprocess
import pkg_resources
import pytest
import os
import time
GET_VERSION = "V1.0.0"
def check_library_installation(library_name):
try:
pkg_resources.get_distribution(library_name)
return 0
except pkg_resources.DistributionNotFound:
print(f"\n\n{library_name} is not installed.\n\n")
print(f"try to use command below:")
print(f"pip install {library_name}")
return 1
if __name__ == '__main__':
if check_library_installation("pytest"):
subprocess.check_call(["pip", "install", "-r", "requirements.txt"])
if check_library_installation("pytest"):
exit(1)
start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
pytest.main()
end_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
report_time = time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime(time.time()))
report_dir = os.path.join(os.getcwd(), "reports")
report_file = os.path.join(report_dir, f"{report_time}report.html")
print(f"Test over, the script version is {GET_VERSION},"
f" start at {start_time}, end at {end_time} \n"
f"=======>{report_file} is saved. \n"
)
input("=======>press [Enter] key to Show logs.")