change: init logger with INFO level

This commit is contained in:
debugtalk
2022-04-22 21:35:38 +08:00
parent 9afe10f816
commit aab9a7de3f
4 changed files with 22 additions and 4 deletions

View File

@@ -73,3 +73,7 @@ jobs:
- name: Run smoketest - rendezvous
run: |
./output/hrp boom examples/hrp/rendezvous_test.json --spawn-count 10 --spawn-rate 10 --loop-count 10
- name: Run hrp convert --pytest
run: ./output/hrp convert examples/postman_echo/request_methods/
- name: Run hrp pytest
run: ./output/hrp pytest examples/postman_echo/request_methods/

View File

@@ -9,7 +9,7 @@ from loguru import logger
from httprunner import __description__, __version__
from httprunner.compat import ensure_cli_args
from httprunner.make import init_make_parser, main_make
from httprunner.utils import ga_client, init_sentry_sdk
from httprunner.utils import ga_client, init_logger, init_sentry_sdk
init_sentry_sdk()
@@ -57,6 +57,8 @@ def main_run(extra_args) -> enum.IntEnum:
def main():
""" API test: parse command line options and run commands.
"""
init_logger()
parser = argparse.ArgumentParser(description=__description__)
parser.add_argument(
"-V", "--version", dest="version", action="store_true", help="show version"

View File

@@ -12,6 +12,7 @@ except ModuleNotFoundError:
USE_ALLURE = False
from loguru import logger
from httprunner.client import HttpSession
from httprunner.config import Config
from httprunner.exceptions import ParamsError, ValidationFailure
@@ -19,7 +20,7 @@ from httprunner.loader import load_project_meta
from httprunner.models import (ProjectMeta, StepResult, TConfig, TestCaseInOut,
TestCaseSummary, TestCaseTime, VariablesMapping)
from httprunner.parser import Parser
from httprunner.utils import merge_variables
from httprunner.utils import LOGGER_FORMAT, init_logger, merge_variables
class SessionRunner(object):
@@ -43,6 +44,7 @@ class SessionRunner(object):
__log_path: Text = ""
def __init(self):
init_logger()
self.__config = self.config.struct()
self.__session_variables = {}
self.__start_at = 0
@@ -188,6 +190,7 @@ class SessionRunner(object):
def test_start(self, param: Dict = None) -> "SessionRunner":
"""main entrance, discovered by pytest"""
print("\n")
self.__init()
self.__parse_config(param)
@@ -200,14 +203,13 @@ class SessionRunner(object):
f"Start to run testcase: {self.__config.name}, TestCase ID: {self.case_id}"
)
log_handler = logger.add(self.__log_path, level="DEBUG")
logger.add(self.__log_path, format=LOGGER_FORMAT, level="DEBUG")
self.__start_at = time.time()
try:
# run step in sequential order
for step in self.teststeps:
self.__run_step(step)
finally:
logger.remove(log_handler)
logger.info(f"generate testcase log: {self.__log_path}")
self.__duration = time.time() - self.__start_at

View File

@@ -5,6 +5,7 @@ import json
import os
import os.path
import platform
import sys
import uuid
from multiprocessing import Queue
from typing import Any, Dict, List, Text
@@ -320,3 +321,12 @@ def gen_cartesian_product(*args: List[Dict]) -> List[Dict]:
product_list.append(product_item_dict)
return product_list
LOGGER_FORMAT = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level}</level> | <level>{message}</level>"
def init_logger():
# set log level to INFO
logger.remove()
logger.add(sys.stderr, format=LOGGER_FORMAT, level="INFO")