cmd执行:
pytest --help #查看pytest.ini
pytest详细使用:https://cloud.tencent.com/developer/article/1640840
"""
pytest测试:
测试文件以test_开头(以_test结尾也可以)
测试类以Test开头,并且不能带有 init 方法
测试函数以test_开头
断言使用基本的assert即可
"""
环境依赖:java8+、jdk1.8
brew install allure pip install pytest pip install allure-pytest
logging模块的详细使用:https://www.cnblogs.com/nancyzhu/p/8551506.html
https://blog.csdn.net/Runner1st/article/details/96481954
1)修改pytest.ini文件
pytest是从pytest.ini中读取log_cli配置的,默认是关闭的
[pytest] log_cli = 1 log_cli_level = INFO log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s) log_cli_date_format=%Y-%m-%d %H:%M:%S
2)用pytest -o方式重写,这个功能在pytest 3.4之后才实现,如下
pytest testcases.py -o log_cli=true -o log_cli_level=INFO
logging模块使用:
logging.basicConfig(level=logging.INFO, filemode=‘a‘, filename=‘logger.log‘,
format=‘%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s‘)
def test_a(): log.info(‘info message‘) log.debug(‘debug message‘) log.warning(‘warning message‘) log.error(‘error message‘) log.critical(‘critical message‘) assert 1, "pass"
allure+logging实例:
currentPath = os.path.dirname(os.path.abspath(__file__)) date = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
"""
filemode=‘a‘,##模式,有w和a,w就是写模式,每次都会重新写日志,覆盖之前的日志
#a是追加模式,默认如果不写的话,就是追加模式
"""
if __name__ == ‘__main__‘: # 使用pytest生成报告:pytest --html=report.html # 使用allure生成报告 report_path = os.path.join(currentPath, ‘results‘, ‘reports‘, str(date)) allure_report_path = os.path.join(currentPath, ‘results‘, ‘allurereport‘, str(date)) test_folder = os.path.join(currentPath, ‘testcases‘) pytest.main([test_folder, ‘--alluredir=%s‘ % (report_path), ‘-o log_cli=true‘]) #-o log_cli_level=INFO os.system(‘/usr/local/Cellar/allure/2.13.5/bin/allure generate %s -o %s/html --clean‘ % (report_path, allure_report_path)) # 替换为本地的 allure 安装路径
pytest使用简单概括[pytest.ini、allure、looging]
原文:https://www.cnblogs.com/lucylu/p/13517426.html