unittest

Python Unittests continue after failure [duplicate]

匿名 (未验证) 提交于 2019-12-03 09:19:38
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Continuing in Python's unittest when an assertion fails 9 answers What's the best way of continuing tests after failure in unittest ? #!/usr/env/bin python2.7 import unittest from fib import fib class FibTests(unittest.TestCase): def test_0(self): self.assertEqual(fib(0), 0) self.assertEqual(fib(1), 1) self.assertEqual(fib(2), 1) self.assertEqual(fib(5), 5) self.assertEqual(fib(10), 55) def test_1(self): self.assertEqual(fib(0), 1) def test_2(self): self.assertEqual(fib(1), 0) self.assertEqual(fib(5)

unittest installation error Could not find a version that satisfies the requirement

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Could someone please help me with this error message: Could not find a version that satisfies the requirement unittest I installed latest Python and PyCharm and try to install the package unittest but get above error. So far my experience with Python is a bit like dll hell ... 回答1: If you tried this: $ pip install unittest Collecting unittest Could not find a version that satisfies the requirement unittest (from versions: ) No matching distribution found for unittest It's normal to have an error because unittest is not a valid package on

Python学习笔记之unittest测试类

独自空忆成欢 提交于 2019-12-03 07:18:42
11-3 雇员:编写一个名为Employee 的类,其方法__init__()接受名、姓和年薪,并将它们都存储在属性中。编写一个名为give_raise()的方法,它默认将年薪增加5000美元,但也能够接受其他的年薪增加量。 为Employee 编写一个测试用例,其中包含两个测试方法:test_give_default_raise()和test_give_custom_raise()。使用方法setUp(),以免在每个测试方法中都创建新的雇员实例。运行这个测试用例,确认两个测试都通过了。 employee.py 1 class Employee(): 2 3 def __init__(self, first_name, last_name, annual_salary): 4 self.first_name = first_name 5 self.last_name = last_name 6 self.annual_salary = annual_salary 7 8 def give_raise(self, annual_salary=5000): 9 self.annual_salary += annual_salary test_employee.py 1 import unittest 2 from employee import Employee 3 4 class

单元测试框架Uinttest一文详解

China☆狼群 提交于 2019-12-03 05:30:30
在前段时间,分享了几篇关于appium基础的博文,再加上期间也有讲到unittest测试框架,所以今天就来一个专题,在appium+python实现的线性代码基础上,引入unittest框架,使代码更简洁。 之前的博客,可以见以下链接快速阅读: 基于Python的Appium环境搭建合集 Genymotion模拟器的安装及脚本制作 Appium Python API 中文版 Appium-Server与Appium-Desktop的区别 单元测试框架Uinttest一文详解 在以上博文中,代码示例,很多只是个线性脚本,没有太多的实用之处,用来写个demo还是可以,但实际运用到产品中,就不行了。脚本还是得引用框架,这样看起来,代码就不会那么乱,更有逻辑性,便于维护。 好了,进入正题,对unittest以及appium还不熟悉的,可以先阅读如上的博文了解,此篇文中,就不赘述了。 unittest代码优化一 优化逻辑: ①将启用服务字段放到初始化当中 ②将输入账号、输入密码、获取当前activity的操作封装成一个个函数 ③在用例中去调用需要执行的函数 示例代码如下: import selenium import time from appium import webdriver from selenium.webdriver.support.ui import

unittest管理测试用例

非 Y 不嫁゛ 提交于 2019-12-03 05:14:21
#coding=utf-8 from selenium import webdriver from time import sleep import unittest  #导入unittest库 import HTMLTestRunner #创建一个类,并且该类继承unittest.case类 class Test_baidu(unittest.TestCase): #初始环境,每一个用例执行时都会先执行这里的代码 def setUp(self): self.dr=webdriver.Chrome()  #调用指定的浏览器并赋值给dr self.dr.maximize_window() self.dr.implicitly_wait(10)  #智能等待作用和sleep一样 self.dr.get('https://www.baidu.com') sleep(2) #测试用例---执行搜索新方硕--测试用例的脚本 def test_case2(self): self.dr.find_element_by_id('kw').send_keys(u'新方硕') sleep(3) #测试用例--执行搜索新东方 def test_case1(self): self.dr.find_element_by_id('kw').send_keys(u'新东方') sleep(3) #还原环境(结束

python-测试报告的输入

こ雲淡風輕ζ 提交于 2019-12-03 04:54:06
本文来源于 : https://www.cnblogs.com/insane-Mr-Li/p/9132078.html 我们整个自动化才是报告的环节基本上分为三个部分: 1.测试用例的准备 2.测试用例的执行 3.测试报告的输出 1.测试用例的准备: 那我们就以搜孤网页做一个简单的用例: from selenium import webdriver import unittest class Case_1(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.maximize_window()#放大浏览器 self.driver.get("https://www.sogou.com/") def test_001(self): self.driver.find_element_by_link_text('微信').click() self.assertIn(self.driver.title,u'搜狗微信搜索_订阅号及文章内容独家收录,一搜即达') def test_002(self): self.driver.find_element_by_link_text('新闻').click() self.assertIn(self.driver.title,u'搜狗新闻 -

Selenium 2自动化测试实战29(组织单元测试用例和discover更多测试用例)

房东的猫 提交于 2019-12-03 04:41:51
一、组织单元测试用例 看看unittest单元测试框架是如何扩展和组织新增的测试用例 以之前的calculator.py文件为例,为其扩展sub()方法,用来计算两个数相减的结果。 #coding:utf-8 #计算器类 class Count(): def __init__(self,a,b): self.a=int(a) self.b=int(b) #计算加法 def sum(self): return self.a+self.b #计算减法 def sub(self): return self.a-self.b 因为对计算器类又新增了 减法功能(sub) ,所以需要针对新功能编写测试用例,扩展后的test.py如下 #coding:utf-8 from Demo1 import Count import unittest class TestSum(unittest.TestCase): def setUp(self): a = input("please input the date:") self.a = int(a) b = input("please input the other date:") self.b = int(b) def testSum(self): self.assertEqual((Count(self.a,self.b).sum()),5,msg

python+unittets框架

被刻印的时光 ゝ 提交于 2019-12-03 04:32:55
本文来源于: https://www.cnblogs.com/insane-Mr-Li/p/9132406.html 我们整个自动化才是报告的环节基本上分为三个部分: 1.测试用例的准备 2.测试用例的执行 3.测试报告的输出 1.测试用例的准备: 那我们就以搜孤网页做一个简单的用例: from selenium import webdriver import unittest class Case_1(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.maximize_window()#放大浏览器 self.driver.get("https://www.sogou.com/") def test_001(self): self.driver.find_element_by_link_text('微信').click() self.assertIn(self.driver.title,u'搜狗微信搜索_订阅号及文章内容独家收录,一搜即达') def test_002(self): self.driver.find_element_by_link_text('新闻').click() self.assertIn(self.driver.title,u'搜狗新闻 -

测试函数——PYTHON编程从入门到实践

孤人 提交于 2019-12-03 03:44:28
更多技术资讯可关注:gzitcast 学习测试,得有测试的代码。下面是一个简单的函数: name_function.py def get_formatted_name(first, last): """Generate a neatly formatted full name.""" full_name = first + ' ' + last return full_name.title()   为核实get_formatted_name()像期望的那样工作,编写一个使用这个函数的程序: [url=] [/url] names.py from name_function import get_formatted_nameprint("Enter 'q' at any time to quit.")while True: first = input("\nPlease give me a first name: ") if first == 'q': break last = input("Please give me a last name: ") if last == 'q': break formatted_name = get_formatted_name(first, last) print("\tNeatly formatted name: " + formatted

Make nose test runner show logging even if tests pass

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using nosetests test.py to run unit tests: import unittest import logging class Test(unittest.TestCase): def test_pass(self): logging.getLogger('do_not_want').info('HIDE THIS') logging.getLogger('test').info('TEST PASS') self.assertEqual(True, True) def test_fail(self): logging.getLogger('do_not_want').info('HIDE THIS') logging.getLogger('test').info('TEST FAIL') self.assertEqual(True, False) When test fails, it prints out all logging info. I can use --logging-filter to filer out only some loggers: nosetests test.py --verbosity=2 -