Closed Vchenhailong closed 1 year ago
Hi, @Vchenhailong !
Can you please share the code of one of your tests where you use the logger (e.g., the one you have shown on the screenshot)?
Hi, @Vchenhailong !
Can you please share the code of one of your tests where you use the logger (e.g., the one you have shown on the screenshot)?
@delatrie
Can be run the following:
#!/usr/local/bin/py3
# -*- coding:utf-8 -*-
"""
@Interpreter: Python 3.10.5
@File: test_runtime.py
@Description:
@Author: hailong.chen
@Date: 2022/8/10 16:51
@ModifiedBy:
"""
import time
import allure
import pytest
from allure_commons import fixture
from selenium.webdriver.common.by import By
from base.common import logger
from cases.website.conftest import choose_app
@pytest.mark.smoke
def test_logical_runtime(browser, choose_app):
"""测试业务逻辑节点的运行时。检测节点包括:
查询设置、加载数据、编辑数据、新增数据、删除数据、提交数据、编辑数据源数据、删除数据源数
据、新增数据源数据、条件、(自定义)循环、循环跳出、循环跳过、排序、变量赋值、子逻辑调用、连
接器和并行网关等
数据源模式包括标准数据源和关联数据源
"""
time.sleep(5)
# 对应页面的运行时测试场景开始
browser.get("https://chltestapp-dialtest-dev.n.onein.cn/ywljjdysjlx")
logger.info("运行时下开始测试绑定有各个节点的业务逻辑")
browser.find_element(By.XPATH, "//span[text()='查询设置节点']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), '查询')]"), "查询设置成功"
logger.info("含查询设置节点的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='编辑节点']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), '1')]"), "编辑数据成功"
logger.info("含编辑数据节点的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='批量编辑的逻辑']").click()
# 已经涉及节点:循环、新增、加载、批量删除、查询设置、变量赋值
assert browser.find_element(By.XPATH, "//p[contains(text(), 'true')]"), "批量编辑成功"
logger.info("含批量编辑节点的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='批量删除的逻辑']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), '0')]"), "批量删除成功"
logger.info("含批量删除节点的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='删除数据节点']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), '1')]"), "删除数据成功"
logger.info("含删除数据节点的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='排序后加载的数据条目']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), '6')]"), "排序成功"
logger.info("含排序节点的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='循环、条件与循环跳过']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), '50')]"), "循环、条件与循环跳过执行成功"
logger.info("含循环、条件与循环跳过节点的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='循环跳出']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), '79')]"), "循环跳出执行成功"
logger.info("含循环跳出节点的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='新增数据源数据']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), '新增数据源数据')]"), "新增数据源数据执行成功"
logger.info("含新增数据源数据节点的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='关联数据源查询与加载分页']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), '张三')]"), "关联数据源查询与加载分页执行成功"
logger.info("关联数据源模式下,查询与加载分页数据的业务逻辑调用成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='调用子流程']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), 'true')]"), "调用子流程节点的逻辑执行成功"
logger.info("含子流程调用节点的业务逻辑执行成功")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='循环节点与连接器调用']").click()
try:
assert browser.find_element(By.XPATH, "//p[contains(text(), '中国')]"), "连接器访问服务正常响应"
logger.info("连接器节点调用`和风天气`的服务成功")
except:
logger.warning("没有正常响应,涉及第三方服务因此忽略结果")
time.sleep(3)
browser.find_element(By.XPATH, "//span[text()='并行网关调用']").click()
assert browser.find_element(By.XPATH, "//p[contains(text(), 'world')]"), "并行网关执行成功"
logger.info("含并行网关节点的业务逻辑调用成功")
# 对应页面的运行时测试场景结束
time.sleep(5)
logger.info("运行时的含各节点的业务逻辑测试完成")
Screenshots file upper referring:
Method of invoke
@Vchenhailong
Please, try to put the following line in your pytest.ini
and run pytest again:
[pytest]
log_level = info
Or run pytest with the following parameter:
pytest --log-level info .....
@delatrie Thanks a lot. It works. 💯
Perhaps, the reason is stdout & stderr are redirected, and also is the relationship of default log-level of Pytest ?
I've set pytest.ini
:
[pytest]
log_cli = False
log_cli_level = INFO
log_cli_format = [%(levelname)s] %(asctime)s - %(filename)s :: %(funcName)s - line %(lineno)s - %(message)s
log_level = INFO
log_file_format = [%(levelname)s] %(asctime)s - %(filename)s :: %(funcName)s - line %(lineno)s - %(message)s
@Vchenhailong
Please, try to put the following line in your
pytest.ini
and run pytest again:[pytest] log_level = info
Or run pytest with the following parameter:
pytest --log-level info .....
BTW... Is there some way to keep the format consistence , or how can I foresee the format of "allure" and change it ?
@delatrie Thanks a lot. It works. 💯
Perhaps, the reason is stdout & stderr are redirected, and also is the relationship of default log-level of Pytest ? I've set
pytest.ini
:[pytest] log_cli = False log_cli_level = INFO log_cli_format = [%(levelname)s] %(asctime)s - %(filename)s :: %(funcName)s - line %(lineno)s - %(message)s log_level = INFO log_file_format = [%(levelname)s] %(asctime)s - %(filename)s :: %(funcName)s - line %(lineno)s - %(message)s
The general rule regarding logging is that allure captures what pytest captures. So, basically, this drills down to pytest logging configuration. The default logging level set up by pytest is WARNING
. You can change the level globally with a config/cli options or in a narrower scope with caplog
fixture.
As for your second question, you can use log_format
and log_date_format
to specify the format globally regardless of a logging destination.
You can find all the details in this article.
Since there is no bug, I'm closing the issue. If you have more questions, please, consider asking them on stackoverflow.com or start a discussion. If you face a bug or have a feature request, feel free to start a new issue.
[Version Infos]
Versions are the same on different OS.
Allure: 2.17.3 Python: 3.10 Pytest: 7.2.0 Jenkins Plugin @ Allure : 2.30.2
[Bug Description / Question] Logs didn't show in allure-report running by Linux. What's the reason?
[Logger Instance Code Snippet]