pytest

Web全自动化测试Python + Pytest+Selenium+ Saucelabs

假如想象 提交于 2019-12-17 15:34:13
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 背景介绍: 关于Web Ui 全自动化测试,我们用简单易学的python语言来编写测试用例;采用Python的单元测试框架Pytest去控制和运行测试用例;采用开源的Web Ui 测试框架Seleniumt提供的API操作界面元素;使用Saucelabs平台提供的各种浏览器。这样我们可以轻松的达到多浏览多测试用例并行运行。 一、环境搭建 关于全局环境 安装Python 安装pip,用于管理和安装python的各类包 关于Sauce Credentials 注册saucelabs账号把SAUCE_USERNAME和AUCE_ACCESS_KEY写到测试代码中 username = "LindaTest" access_key = "9f555be7-59c9-4b6d-a3aa-b4efc7646d9b" Project 依赖环境 我推荐使用virtualenv创建独立的python环境给自动化测试的Project 安装virtualenv pip.exe install virtualenv 进入自动化测试的Project 的根目录,创建virtualenv venv virtualenv venv 安装项目相关的依赖包 pip.exe install -r requirements.txt

PATH issue with pytest 'ImportError: No module named YadaYadaYada'

点点圈 提交于 2019-12-16 20:51:26
问题 I used easy_install to install pytest on a mac and started writing tests for a project with a file structure likes so: repo/ repo/app.py repo/settings.py repo/models.py repo/tests/ repo/tests/test_app.py run py.test while in the repo directory, everything behaves as you would expect but when I try that same thing on either linux or windows (both have pytest 2.2.3 on them) it barks whenever it hits its first import of something from my application path. Say for instance from app import some

pytest中怎么实现参数化?

一曲冷凌霜 提交于 2019-12-16 14:09:18
我们在组自动化项目中,肯定会遇到需要数据驱动的地方,在unittest中我们直接采用ddt的方式,但是在pytest中我们不能用ddt来实现,所以我们采用了参数化的方式来实现 那么具体怎么完成这个参数化呢? 我们还是使用pytest中的标记功能 例如: @pytest.mark.parametrize("data", test_login_datas.login_toast_error_data)  """  data 这个参数用来接收后面这个列表中的值  """ def test_name_error_login(self, data, init_driver): """    这里面的data必须和上面标记中的data同名 用户名错误 """ init_driver[1].login(data["name"], data["passwd"]) assert(init_driver[1].toast_error() == data["expect"]) 来源: https://www.cnblogs.com/LCboss/p/12028209.html

Flask-单元测试

时光总嘲笑我的痴心妄想 提交于 2019-12-16 13:47:39
Flask-单元测试 敏捷开发(agile development) scrum 结对编程 测试驱动开发(TDD): Test driven development 单元测试(unit testing)是开发者自己编写的一小段代码,用于检验被测代码的一个很小的、很明确的功能是否正确。通常而言,一个单元测试是用于判断某个 特定条件(或者场景)下某个特定函数 的行为。 注意单元测试是开发人员自己负责 unittest Pytest是 python的一种unittest框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高。 执行测试过程中可以将某些测试跳过,或者对某些预期失败的case标记成失败 能够支持简单的单元测试和复杂的功能测试 支持重复执行失败的case 支持运行由nose, unittest编写的测试case 具有很多第三方插件,并且可以自定义扩展 方便的和持续集成工具集成 支持参数化 pytest fixture用途 1.做测试前后的初始化设置,如测试数据准备,链接数据库,打开浏览器等这些操作都可以使用fixture来实现 2.测试用例的前置条件可以使用fixture实现 3.支持经典的xunit fixture ,像unittest使用的setup和teardown 4

Selenium 4 Python的最佳测试框架

亡梦爱人 提交于 2019-12-14 10:56:11
随着Python语言的使用越来越流行,基于Python的测试自动化框架也越来越流行。在项目选择最佳框架时,开发人员和测试人员会有些无法下手。做出选择是应该判断很多事情,框架的脚本质量,测试用例的简单性以及运行模块并找出其缺点的技术。这篇文章总结了测试自动化领域,适合Web端自动化框架(基于Python语言)以及它们相对于其他方面的优缺点。因此,可以帮助一些人根据需要和实际情况选择合适的的Python框架进行测试自动化。 Robot Framework Robot Framework主要用于测试驱动的开发以及验收测试,它是最好的测试框架之一。虽然是用Python开发的,它也可以运行的 IronPython ,这是 .NET 为基础的和基于 Java 的 Jython 的。Robot Framework作为Python框架可在所有平台上兼容:Windows,MacOS或Linux。 前提 首先,只有安装了Python 2.7.14或更高版本的Python,您才能使用Robot Framework(RF)。 您还需要安装“pip”或其他python软件包管理器。 最后,必须下载一个IDE。在开发人员中流行的工具是PyCharm社区版。 Robot Framework的优缺点是什么?让我们看一下与其他Python框架相比,作为测试自动化框架的Robot的优缺点是什么。 优点

Selenium 4 Python的最佳测试框架

核能气质少年 提交于 2019-12-14 10:18:13
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 随着Python语言的使用越来越流行,基于Python的测试自动化框架也越来越流行。在项目选择最佳框架时,开发人员和测试人员会有些无法下手。做出选择是应该判断很多事情,框架的脚本质量,测试用例的简单性以及运行模块并找出其缺点的技术。这篇文章总结了测试自动化领域,适合Web端自动化框架(基于Python语言)以及它们相对于其他方面的优缺点。因此,可以帮助一些人根据需要和实际情况选择合适的的Python框架进行测试自动化。 Robot Framework Robot Framework主要用于测试驱动的开发以及验收测试,它是最好的测试框架之一。虽然是用Python开发的,它也可以运行的 IronPython ,这是 .NET 为基础的和基于 Java 的 Jython 的。Robot Framework作为Python框架可在所有平台上兼容:Windows,MacOS或Linux。 前提 首先,只有安装了Python 2.7.14或更高版本的Python,您才能使用Robot Framework(RF)。 您还需要安装“pip”或其他python软件包管理器。 最后,必须下载一个IDE。在开发人员中流行的工具是PyCharm社区版。 Robot Framework的优缺点是什么

How can I prevent self from eating one of my test parameters?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 03:36:51
问题 I have in my test module: import pytest from src.model_code.central import AgentBasic class AgentBasicTestee(AgentBasic): pass @pytest.fixture() def agentBasic(): return AgentBasicTestee() @pytest.mark.parametrize('alpha, beta, delta, expected', [ (2, 1, 1, pytest.approx(0.5)), (2, 2, 2, pytest.approx(-0.9375 / 0.75)), ]) def test_b3(agentBasic, AgentCOne,alpha, beta, delta, expected): assert(agentBasic.b3(alpha, beta, delta) == expected) and in my import module from src.model_code.crra

using setup_class for initialization “conflicts” with parametrize options

纵饮孤独 提交于 2019-12-14 03:18:24
问题 I have this file: import numpy as np class Variables(object): def __init__(self, var_name, the_method): self.var_name = var_name self.the_method = the_method def evaluate_v(self): var_name, the_method = self.var_name, self.the_method if the_method == 'Average': return np.average(var_name) and this test file: import unittest import pytest import numpy as np from .variables import Variables class TestVariables(): @classmethod def setup_class(cls): var_name = np.array([1, 2, 3]) the_method =

How to put a module in a test harness with pytest?

半城伤御伤魂 提交于 2019-12-14 03:11:04
问题 let's say that I have a file called boop.py that reads: import module_a import sys def boop(value): val = module_a.boop_it(value) # ... return val My questions are: when I'm doing the tests for this, how can I make module_a be a dummy module? I understand I need to isolate the dependencies. I just don't understand the mechanics of it Is it necessary to isolate it entirely? If I don't, will it come to bite me? Note that this is all legacy code, that already exists and has years of history 回答1:

Attribute error message is getting displayed while performing any action

混江龙づ霸主 提交于 2019-12-14 02:30:00
问题 I am trying to generate allure report using Python Selenium framework. On executing the command from CMD: pytest --alluredir= /path for report directory Error message: severities = [x.value for x in list(allure.severity_level)] AttributeError: module 'allure' has no attribute 'severity_level' is getting displayed 来源: https://stackoverflow.com/questions/57722651/attribute-error-message-is-getting-displayed-while-performing-any-action