pytest

trying to make paths work - attempted relative import beyond top-level package

筅森魡賤 提交于 2020-04-12 16:09:47
问题 I can't make this work.. My structure is: program_name/ __init__.py setup.py src/ __init__.py Process/ __init__.py thefile.py tests/ __init__.py thetest.py thetest.py: from ..src.Process.thefile.py import sth Running: pytest ./tests/thetest.py from program_name gives : ValueError: attempted relative import beyond top-level package I tried also other approaches but i am receiving various errors. But I would expect for the above to work. 回答1: ValueError: Attempted relative import in non-package

.coveragerc unable to locate files I want omitted

走远了吗. 提交于 2020-04-11 12:25:28
问题 I am using tox to automatically run my tests using pytest and pytest-cov plugin. However, I'm getting coverage reports for the files I omitted in .coveragerc : (env) alex@smartalex-pc:~/.repos/codelib/github/project$ tox [...] ../../../tests/test_module1.py::test_func PASSED [ 3%] [...] ../../../tests/test_module2.py::test_func PASSED [100%] ----------- coverage: platform linux, python 3.6.7-final-0 ----------- Name Stmts Miss Cover ------------------------------------------------------------

Selenium login test doesn't accept pytest fixtures for login or refuses to connect

萝らか妹 提交于 2020-04-10 09:09:55
问题 I'm getting desperate because I can't seem to find a solution for what I thought would be used by everyone out there. I want to test a simple login with selenium and pytest with a live_server url. According to pytest-django doc, a simple fixture called live_server should do the trick (https://pytest-django.readthedocs.io/en/latest/helpers.html#live-server). Unfortunately when I pass this fixture to my test and try to visit my website with it I get: localhost refused to connect for example for

Allure安装及使用

只愿长相守 提交于 2020-04-07 19:58:52
Allure是一个独立的报告插件,生成美观易读的报告 在Python3版本中,安装Allure方法: 打开cmd,输入pip install allure-pytest即安装好了。 报告转html工具安装 allure-2.6.0.zip已经下载了,放在了E:\progromes\allure-2.7.0这个目录下 将压缩包内的bin目录配置到path系统环境变量 在项目的使用 1, 配置文件中, addopts = -s --alluredir=./report --reruns 0 2,进入report上级目录,即点击一下你的项目名,在Terminal中执行命令 allure generate report/ -o report/html --clean 等3秒左右,在提示下,输入 pytest 结果 report目录下会生成index.html文件,即为可视化报告 来源: https://www.cnblogs.com/noon-12/p/12655438.html

pytest+jenkins安装+allure导出报告

心已入冬 提交于 2020-04-07 04:01:41
环境安装: windows7+64位 pytest :4.0.2 allure 的安装 : allure 的 python 库 pytest-allure-adaptor jenkins 的安装 :2.138.2 JDK 1.8 一、 pytest pytest的安装不做说明,可以通过pytest --version查看安装的版本 二、安装 Allure Pytest Adaptor Allure Pytest Adaptor是Pytest的一个插件,可以通过它生成Allure所需要的用于生成测试报告的数据 pip install pytest-allure-adaptor 三、jenkins的简单安装 前提:注意JDK的版本问题,本测试使用的是1.8的版本 如已安装,通过java -version检查版本 1.安装jenkins jenkins默认安装在c盘 C:\Users\Administrator\.jenkins下,但由于权限的问题,最好安装在其他位置。 新建一个系统变量:JENKINS_HOME,值为D:\jenkins,或者其他目录也可以。再将此路径添加至Path里。 jenkins的下载地址: https://jenkins.io/download/ 选择的是2.138.2的版本 选择的是jenkins.war 下载成功后,将

接口自动化测试框架开发 (pytest+allure+aiohttp+ 用例自动生成)

孤街浪徒 提交于 2020-04-06 22:46:22
近期准备优先做接口测试的覆盖,为此需要开发一个测试框架,经过思考,这次依然想做点儿不一样的东西。 接口测试是比较讲究效率的,测试人员会希望很快能得到结果反馈,然而接口的数量一般都很多,而且会越来越多,所以提高执行效率很有必要 接口测试的用例其实也可以用来兼做简单的压力测试,而压力测试需要并发 接口测试的用例有很多重复的东西,测试人员应该只需要关注接口测试的设计,这些重复劳动最好自动化来做 pytest和allure太好用了,新框架要集成它们 接口测试的用例应该尽量简洁,最好用yaml,这样数据能直接映射为请求数据,写起用例来跟做填空题一样,便于向没有自动化经验的成员推广 加上我对Python的协程很感兴趣,也学了一段时间,一直希望学以致用,所以http请求我决定用aiohttp来实现。 但是pytest是不支持事件循环的,如果想把它们结合还需要一番功夫。于是继续思考,思考的结果是其实我可以把整个事情分为两部分。 第一部分,读取yaml测试用例,http请求测试接口,收集测试数据。 第二部分,根据测试数据,动态生成pytest认可的测试用例,然后执行,生成测试报告。 这样一来,两者就能完美结合了,也完美符合我所做的设想。想法既定,接着 就是实现了。 第一部分(整个过程都要求是异步非阻塞的) 读取yaml测试用例 一份简单的用例模板我是这样设计的,这样的好处是,参数名和aiohttp

pytest第一节

时光怂恿深爱的人放手 提交于 2020-04-06 21:43:55
python鄙视链:pytest>uniitest>rebotframe>流水账>hello word 进了新公司,本来用unittest框架做自动化的,但是因为报告不美观,比不上allure,被老板要求要使用pytest框架。才知道原来还有这么一条鄙视链。 还有什么可说的呢?盘它 1.安装 pip install -U pytest pytest 运行规则:文件名和函数都以test_开头。测试类以Test开头,且不能有__init__方法。断言assert. 下载allure https://github.com/allure-framework/allure2/releases ,把解压后的 bin 目录添加到环境变量的 PATH 中。 #test.py #the content of test.pyimport pytestimport csv,ospath=os.getcwd()# print(path)datapath=path+"\config\config1.csv"# print(datapath)file=open(datapath,"r")table=csv.reader(file)for row in table: if row[1]=="1": print(row[0]) # pytest.main([row[0],"-s", "--html=test

pytest跳过测试函数

☆樱花仙子☆ 提交于 2020-04-06 12:30:25
使用方法: @pytest.mark.skipif(condition,reason=None) 参数: condition:跳过的条件,True(跳过、不执行)/False(不跳过、执行),必传参数 reason:标注原因 class test_skip: n=5 @pytest.mark.skipif(2 > 1, reason="如果条件为false就跳过") def test_a(self): print("跳过") def test_b(self): print("不跳过") @pytest.mark.skipif(n > 6, reason="如果条件为false就跳过") # 条件为boolean值,True(跳过)/False(不跳过/执行) def test_c(self): print("不跳过")    来源: oschina 链接: https://my.oschina.net/u/4341660/blog/3220157

适用于Mac电脑的Python开发工具哪款好用?

蹲街弑〆低调 提交于 2020-04-05 20:58:48
适用于Mac电脑的Python开发工具哪款好用?WingPro 7 Mac版好用吗?wingpro mac破解版是一款跨平台 Python IDE 系列通过强大的集成编辑,调试,单元测试和项目管理功能,使Python开发变得更加容易。Wing可在Windows,Linux和OS X上运行,可用于开发用于Web,桌面,科学,数据分析,嵌入式脚本和其他应用程序的任何类型的Python代码。 wingpro mac破解版功能介绍 强大的调试器 WingIDE Pro 6 for Mac 破解版的调试器可以轻松修复错误并以交互方式编写新代码。使用条件断点来隔离问题,然后逐步执行代码,检查数据,观察值,从Debug Probe的命令行进行交互,以及递归调试。您可以调试从IDE启动的多进程和多线程代码,托管在Web框架中,从嵌入式Python实例调用或在远程系统上调用。 智能编辑器 WingIDE Pro 6 for Mac 破解版的编辑器通过适合上下文的自动完成和文档,调用辅助,自动编辑,重构,代码折叠,多选,可自定义的内联代码片段,书签等来加速交互式Python开发。Wing可以模拟vi,emacs,Eclipse,Visual Studio和Xcode。 简单的代码导航 WingIDE Pro 6 for Mac 破解版通过goto-definition,查找用途,在项目中查找符号