我正在使用pytest-expect进行软断言或延迟断言。 因此,在运行测试时,尽管在失败的步骤中未将测试报告为在魅力报告中失败,但在魅力报告中却未显示该测试。
我正在使用allure-pytest报告使用硒Webdriver进行集成测试时的测试。
有没有一种方法可以设置步骤状态?
我想在allure-python的stop_step函数上创建一个钩子,但是没有用。也许我用错了! 我想到将其用作python日志记录,并且在record.levelname.lower()=='error'时失败的步骤。
下面是conftest.py的内容:
class AllureLoggingHandler(logging.Handler):
def log(self, message):
with allure.step('Log {}'.format(message)):
pass
def emit(self, record):
if record.levelname.lower() == 'error':
@allure_commons.hookimpl(hookwrapper=True)
def stop_step(self, uuid):
self.allure_logger.stop_step(uuid,
status=Status.FAILED)
self.log("({}) -> {}".format(record.levelname,record.getMessage()))
class AllureCatchLogs:
def __init__(self):
self.rootlogger = logging.getLogger()
self.allurehandler = AllureLoggingHandler()
def __enter__(self):
if self.allurehandler not in self.rootlogger.handlers:
self.rootlogger.addHandler(self.allurehandler)
def __exit__(self, exc_type, exc_value, traceback):
self.rootlogger.removeHandler(self.allurehandler)
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_setup():
with AllureCatchLogs():
yield
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call():
with AllureCatchLogs():
yield
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_teardown():
with AllureCatchLogs():
yield
---contents of my test_something.py
with allure.step('Checking user count.'):
expect(num_of_users == 0, 'some message fr expect')
num_of_users = 1
with allure.step('Checking user count._ 12'):
logging.info("checking 2nd step run")
为此,我期望步骤:具有allure.step('正在检查用户计数。'):失败,但显示为绿色对勾。