pytest demo and log format
Posted mftang2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pytest demo and log format相关的知识,希望对你有一定的参考价值。
import pytest import allure import sys,os import logging import datetime def logInit(): now_time = datetime.datetime.now() filePath = os.getcwd() + "\\log\\" if os.path.exists(filePath) is False: os.makedirs(filePath) logFile = filePath + now_time.strftime("%Y%m%d_%H%M%S") +".log" logging.basicConfig(filename=logFile, filemode="w", format="%(asctime)s -- [line:%(lineno)d] -- %(levelname)s -- %(filename)s -- %(message)s", level=logging.DEBUG) logInit() @allure.feature(‘Manual overide testcase ‘) class TestStringMethods(): @classmethod def setup_class(cls): logging.info("setup class") @classmethod def teardown_class(cls): logging.info("teardown class") @allure.feature(‘test_demo1‘) @allure.severity(‘blocker‘) def test_demo_0_1(self): a = 10 b = 11 assert a is not b logging.info("=================test_demo_0_1===============") @allure.feature(‘test_demo1‘) @allure.severity(‘blocker‘) def test_demo_0_2(self): a = 11 b = 11 assert a is b logging.error("assert a = %d is b = %d" %(a,b)) if __name__ == ‘__main__‘: pytest.main()
以上是关于pytest demo and log format的主要内容,如果未能解决你的问题,请参考以下文章
pytest + yaml 框架 -9.logging日志输出和保存