fix: allure ModuleNotFoundError

This commit is contained in:
debugtalk
2020-05-28 18:58:49 +08:00
parent 63925b9c25
commit e45c83cb5f

View File

@@ -4,7 +4,13 @@ import uuid
from datetime import datetime from datetime import datetime
from typing import List, Dict, Text from typing import List, Dict, Text
import allure try:
import allure
USE_ALLURE = True
except ModuleNotFoundError:
USE_ALLURE = False
from loguru import logger from loguru import logger
from httprunner import utils, exceptions from httprunner import utils, exceptions
@@ -236,7 +242,10 @@ class HttpRunner(object):
step.variables, self.__project_meta.functions step.variables, self.__project_meta.functions
) )
# run step # run step
with allure.step(f"step: {step.name}"): if USE_ALLURE:
with allure.step(f"step: {step.name}"):
extract_mapping = self.__run_step(step)
else:
extract_mapping = self.__run_step(step) extract_mapping = self.__run_step(step)
# save extracted variables to session variables # save extracted variables to session variables
self.__session_variables.update(extract_mapping) self.__session_variables.update(extract_mapping)
@@ -312,9 +321,10 @@ class HttpRunner(object):
self.config.name, variables, self.__project_meta.functions self.config.name, variables, self.__project_meta.functions
) )
# update allure report meta if USE_ALLURE:
allure.dynamic.title(self.config.name) # update allure report meta
allure.dynamic.description(f"TestCase ID: {self.__case_id}") allure.dynamic.title(self.config.name)
allure.dynamic.description(f"TestCase ID: {self.__case_id}")
logger.info( logger.info(
f"Start to run testcase: {self.config.name}, TestCase ID: {self.__case_id}" f"Start to run testcase: {self.config.name}, TestCase ID: {self.__case_id}"