pytest

自动化不知如何参数化?xlrd来帮你解决

巧了我就是萌 提交于 2020-08-05 09:25:02
平时在做自动化测试的时候,一直都是要求数据与业务逻辑分离。把测试数据都写在业务里面的话,比较混杂。为了方便管理测试数据,所以引入了python的一个扩展库--xlrd。该库使用简单,能满足自动化测试的数据分离的需求。 闲语少聊,我们直接来看,xlrd是如何完成数据读取的。 安装 安装很简单,方式①:直接命令pip install xlrd;方式②:在Pycharm中直接安装即可。 基础命令 ①打开excel文件并创建对象 excel_object = xlrd.open_workbook(excel_path) ②根据工作表名称获取数据 sheet_object = excel_object.sheet_by_name('Sheet1') ③获取excel文件中所有工作表名称 print(excel_object.sheet_names()) ④获取有效行数 row_nrows = sheet_object.nrows ⑤获取有效列数 col_ncols = sheet_object.ncols ⑥获取当前行的单元格长度 row_length = sheet_object.row_len(1) ⑦获取第一行数据 rows_cell_value = sheet_object.row_values(0) ⑧获取坐标为第一行、第一列单元格数据 row_cell_value1 =

PyTest: Auto delete temporary directory created with tmpdir_factory

不想你离开。 提交于 2020-08-05 05:35:19
问题 I'm trying to create a temporary directory with a specific name (eg, "data") for all tests within a module using PyTest's tmpdir_factory similar to the tutorial: @pytest.fixture(scope='module') def project_file(self, tmpdir_factory): return tmpdir_factory.mktemp("data") I'm using the temporary directory in some tests within the module successfully. However, the directory still exists after running the tests and when I run them again, I get a failure because I cannot create a new temporary

Scrapy raises ReactorNotRestartable when CrawlerProcess is ran twice

喜你入骨 提交于 2020-08-03 05:58:45
问题 I have some code which looks something like this: def run(spider_name, settings): runner = CrawlerProcess(settings) runner.crawl(spider_name) runner.start() return True I have two py.test tests which each call run(), when the second test executes I get the following error. runner.start() ../../.virtualenvs/scrape-service/lib/python3.6/site-packages/scrapy/crawler.py:291: in start reactor.run(installSignalHandlers=False) # blocking call ../../.virtualenvs/scrape-service/lib/python3.6/site

Scrapy raises ReactorNotRestartable when CrawlerProcess is ran twice

痞子三分冷 提交于 2020-08-03 05:58:12
问题 I have some code which looks something like this: def run(spider_name, settings): runner = CrawlerProcess(settings) runner.crawl(spider_name) runner.start() return True I have two py.test tests which each call run(), when the second test executes I get the following error. runner.start() ../../.virtualenvs/scrape-service/lib/python3.6/site-packages/scrapy/crawler.py:291: in start reactor.run(installSignalHandlers=False) # blocking call ../../.virtualenvs/scrape-service/lib/python3.6/site

pass fixture to test class in pytest

别等时光非礼了梦想. 提交于 2020-08-02 16:33:01
问题 Consider the following pseudocode demonstrating my question: import pytest @pytest.fixture def param1(): # return smth yield "wilma" @pytest.fixture def param2(): # return smth yield "fred" @pytest.fixture def bar(param1, param2): #do smth return [Bar(param1, param2), Bar(param1, param2)] @pytest.fixture def first_bar(bar): return bar[0] class Test_first_bar: # FIXME: how do I do that? #def setup_smth???(self, first_bar): # self.bar = first_bar def test_first_bar_has_wilma(self): # some

pass fixture to test class in pytest

假装没事ソ 提交于 2020-08-02 16:32:13
问题 Consider the following pseudocode demonstrating my question: import pytest @pytest.fixture def param1(): # return smth yield "wilma" @pytest.fixture def param2(): # return smth yield "fred" @pytest.fixture def bar(param1, param2): #do smth return [Bar(param1, param2), Bar(param1, param2)] @pytest.fixture def first_bar(bar): return bar[0] class Test_first_bar: # FIXME: how do I do that? #def setup_smth???(self, first_bar): # self.bar = first_bar def test_first_bar_has_wilma(self): # some

Getting error ImportMismatchError while running py.test

*爱你&永不变心* 提交于 2020-07-31 06:57:34
问题 When I am running tests locally its working fine, but after creating the docker and running inside the container I am getting below error. /usr/local/lib/python3.5/site-packages/_pytest/config.py:325: in _getconftestmodules return self._path2confmods[path] E KeyError: local('/apis/db/tests') During handling of the above exception, another exception occurred: /usr/local/lib/python3.5/site-packages/_pytest/config.py:356: in _importconftest return self._conftestpath2mod[conftestpath] E KeyError:

Getting error ImportMismatchError while running py.test

人盡茶涼 提交于 2020-07-31 06:56:38
问题 When I am running tests locally its working fine, but after creating the docker and running inside the container I am getting below error. /usr/local/lib/python3.5/site-packages/_pytest/config.py:325: in _getconftestmodules return self._path2confmods[path] E KeyError: local('/apis/db/tests') During handling of the above exception, another exception occurred: /usr/local/lib/python3.5/site-packages/_pytest/config.py:356: in _importconftest return self._conftestpath2mod[conftestpath] E KeyError:

自从学会了Python自动化Pytest框架,领导再也不敢在我背后指手划脚了

ぐ巨炮叔叔 提交于 2020-07-29 10:28:19
前言 大家都知道Python有自带的单元测试框架unittest,那为什么还要学习Pytest呢?先了解下Pytest优点 pytest: pytest是一个非常成熟的全功能的Python测试框架,是unittest框架的扩展,主要特点有以下几点: 1、简单灵活,非常方便的组织自动化测试用例; 2、支持参数化,可以细粒度地控制要测试的测试用例; 3、能够支持简单的单元测试和复杂的功能测试,比如web端selenium/移动端appnium等自动化测试、request接口自动化测试 4、pytest具有很多第三方插件,并且可以自定义扩展,比如测试报告生成,失败重运行机制 5、测试用例的skip和fail处理; 6、结合业界最美的测试报告allure+Jenkins,持续集成 selenium : 基于 JavaScript 代码库的自动化测试框架,通过脚本语言,模拟用户行为操作,最接近用户真实场景,实现对 web 自动测试。 Selenium ,是目前的最火爆企业最主流的 webUI 自动化框架 环境搭建 pip install -U pytest pytest-xdist # 多线程 pip install -U pytest-rerunfailures # 重试运行 cases pip install pytest-html # 生成测试报告 pytest --version #

自动化测试之Jenkins配置

空扰寡人 提交于 2020-07-29 08:47:54
UI自动化所用到的技术: selenium:不解释。 pytest:单元测试框架,因为它可以全局的配置浏览器驱动的开启与关闭,而且有很多好用的扩展插件,更适合来做UI自动化。 pytest-html:生成HTML测试报告,可以配置用例失败自动截图,这一点对UI自动化很重要。 pytest-rerunfailures:可以实现用例的失败重跑,这一点对UI自动化也很重要。 Selenium-page-objects:我封装的page objects库,以前也有介绍,让你编写page层更加简单。 Git/Bitbucket:我们的测试代码提交到Bitbucket上管理。 加入我们,群,642830685,领取最新软件测试资料大厂面试和Python自动化、接口、框架搭建学习资料! Jenkin做什么? 接下来才是重点,Jenkins主要用来运行UI自动化测试。接下来介绍一下我的配置。 配置Git,连接Bitbucket,检查项目代码更新。 定时任务,设置为每天晚上22:00运行。 构建命令,拉取代码,并运行所有用例。 设置HTML测试报告的路径 设置XML测试报告的路径。 配置发邮件功能。 大致效果如下: 可以点击HTML Report查看HTML报告,最新结果可以看到项目XML格式的报告。测试趋势图,这个是基于XML报告插件生成的。 在Jenkins中查看测试HTML测试报告。 当然