pytest

基于python2+selenium3+pytest4的UI自动化框架

吃可爱长大的小学妹 提交于 2020-02-16 19:35:44
环境:Python2.7.10, selenium3.141.0, pytest4.6.6, pytest-html1.22.0, Windows-7-6.1.7601-SP1 特点: - 二次封装了selenium,编写Case更加方便。 - 采用PO设计思想,一个页面一个Page.py,并在其中定义元素和操作方法;在TestCase中直接调用页面中封装好的操作方法操作页面。 - 一次测试只启动一次浏览器,节约时间提高效率(适合公司业务的才是最好的)。 - 增强pytest-html报告内容,加入失败截图、用例描述列、运行日志。 - 支持命令行参数。 - 支持邮件发送报告。 目录结构: - config - config.py:存放全局变量,各种配置、driver等 - drive:各浏览器驱动文件,如chromedriver.exe - file - download:下载文件夹 - screenshot:截图文件夹 - upload:上传文件夹 - page_object:一个页面一个.py,存放页面对象、操作方法 - base_page.py:基础页面,封装了selenium的各种操作 - hao123_page.py:hao123页面 - home_page.py:百度首页 - news_page.py:新闻首页 - search_page.py:搜索结果页 -

How to use logging, pytest fixture and capsys?

心已入冬 提交于 2020-02-13 08:37:08
问题 I am trying to unit-test some algorithm that uses logging library. I have a fixture that creates a logger. In my 1st test case , I do not use this fixture and uses a print to log to stdout. This test case passes . In my 2nd test case , I use this fixture, but not as documented in pytest doc. I just call the associated function in my test to get the logger. Then I use the logger to log to stdout. This test case passes . In my 3rd test case , I use this fixture as documented in pytest doc. The

How to use logging, pytest fixture and capsys?

≯℡__Kan透↙ 提交于 2020-02-13 08:36:27
问题 I am trying to unit-test some algorithm that uses logging library. I have a fixture that creates a logger. In my 1st test case , I do not use this fixture and uses a print to log to stdout. This test case passes . In my 2nd test case , I use this fixture, but not as documented in pytest doc. I just call the associated function in my test to get the logger. Then I use the logger to log to stdout. This test case passes . In my 3rd test case , I use this fixture as documented in pytest doc. The

pytest问题:

孤街醉人 提交于 2020-02-12 19:30:21
安装 pytest测试框架: pip install pytest 安装插件: pip install pytest-cov pip install pytest-pep8 pip install pytest-flakes 来源: CSDN 作者: wun123 链接: https://blog.csdn.net/wun123/article/details/104282731

Pytest常用命令

本小妞迷上赌 提交于 2020-02-12 12:22:40
Pytest -v 或 Pytest -vv 显示具体的详情信息,一般显示错误的位置及错误的详细信息**。Pytest --verbose** 等价于 pytest -v ,如图下 Pytest --collect-only 收集可执行的案例 Pytest -k 案例名称 表示运行指定的案例,例如 pytest -k “_002” 表示指定运行含有002案例的测试案例 在test_file01文件中命名为test_001() 在test_file02文件中命名为test_two_001() ,运行的时候编辑命令 pytest -k “_001” 所以它会运行相关名称下的案例 Pytest -s 等价于 pytest --capture=no 可以捕获print函数的输出 pytest --last-failed 等价于 pytest --lf 可以筛选失败的案例,不会继续运行失败之后的案例,如下一个test_001被deselected而test_file02.py文件则被跳过。 Pytest --ff 等价于 pytest --failed-first 表示可以运行完失败的案例后继续执行后续的案例,如下执行了test_file01.py和test_file02.py两个文件共4个案例 pytest -q 等价于 Pytest --quiet 可以简化输出信息,pytest

Bug:No module named 'pytest'

a 夏天 提交于 2020-02-08 18:35:13
在测试模型时遇到Bug:No module named ‘pytest’ 我的场景:pycharm下运行一个测试深度学习模型的python代码。我的代码名称为test_exp.py 出现bug的原因 :.py文件的开头出现了test这个单词。 之所以是强调开头,是因为我重新尝试了一下model_test的文件名,是可以通过运行的 注意是test这个整体,如果是testr,testpp等等都是不会报错的 直接使用test这个单词是不会出错的,这也是我觉得神奇的地方。也就是test.py是OK的。 解决办法: 把文件名开头的test换掉,或者放到后面去即可,或者直接改成test 具体原因 更深层的原因,为什么那么命名会出现这些问题呢,为啥pytest就冒出来了呢?我暂时也还不知道,等以后知道了再来记录吧 来源: CSDN 作者: qq_41936559 链接: https://blog.csdn.net/qq_41936559/article/details/104226013

pytest 框架之pytest-html报告生成

我与影子孤独终老i 提交于 2020-02-08 13:55:26
一、关于安装 pytest-html属于pytest的一个插件,使用它需要先安装 pip install pytest-html pytest可以生成多种样式的结果: 生成 JunitXML 格式的测试报告,命令 : --junitxml= path 生成 ResultLog 格式的测试报告,命令: --resultlog=report/log.txt 生成 Html 格式的测试报告,命令: --html=OutPuts/reports/report.html (相对路径) 二、生成html报告 import pytest if __name__ == '__main__':  # 生成pytest-html报告 pytest.main(['-s', '-v', '--html=Outputs/reports/report.html']) 生成的测试报告位置: 打开测试报告: *******尊重作者,本文是本人转载自: https://www.cnblogs.com/xiaogongjin/ ******* 来源: https://www.cnblogs.com/shouhu/p/12276140.html

解决pytest在pycharm中报错:NameError: name 'pytest' is not defined

一笑奈何 提交于 2020-02-06 10:43:53
在 pycharm CE 2019.2 中配置pytest环境时,遇到了如下报错: esting started at 上午 11 : 32 . . . / usr / local / bin / python3 . 7 "/Applications/PyCharm CE.app/Contents/helpers/pycharm/_jb_pytest_runner.py" - - path / Users / tu / Desktop / UI / test_q . py Launching pytest with arguments / Users / tu / Desktop / UI / test_q . py in / Users / tu / Desktop / UI Traceback ( most recent call last ) : File "/Applications/PyCharm CE.app/Contents/helpers/pycharm/_jb_pytest_runner.py" , line 45 , in < module > pytest . main ( args , plugins_to_load ) NameError : name 'pytest' is not defined Process finished with exit

vscode 如何调试pytest

☆樱花仙子☆ 提交于 2020-02-04 10:35:39
pytest是比较好用的测试框架, 用vscode 调试很方便但是需要配置一下launch.json 在configurations里加上下面的节点. 百度找了半天的中文网页没找到, 后来去http://cn.bing.com/ 国外网站搜到了 原文地址 https://keathmilligan.net/debugging-pytest-in-vscode { "version" : "0.2.0" , "configurations" : [ { "name" : "PyTest" , "type" : "python" , "request" : "launch" , "stopOnEntry" : false , "pythonPath" : "${config:python.pythonPath}" , "module" : "pytest" , "args" : [ "-sv" , "--disable-pytest-warnings" , "--html=report.html" ] , "cwd" : "${workspaceRoot}" , "env" : { } , "envFile" : "${workspaceRoot}/.env" /*"debugOptions": [ "WaitOnAbnormalExit", "WaitOnNormalExit",

Pytest: running tests multiple times with different input data

孤街浪徒 提交于 2020-02-03 10:23:28
问题 I want to run through a collection of test functions with different fixtures for each run. Generally, the solutions suggested on Stack Overflow, documentation and in blog posts fall under two categories. One is by parametrizing the fixture: @pytest.fixture(params=list_of_cases) def some_case(request): return request.param The other is by calling metafunc.parametrize in order to generate multiple tests: def pytest_generate_tests(metafunc): metafunc.parametrize('some_case', list_of_cases) The