目录
4.unittest什么时候报Error,什么时候报Fail?
一、unittest
1.参考学习链接:
2.unittest测试框架文档;
unittest --- 单元测试框架 — Python 3.10.4 文档
(1)测试用例运行的顺序,跟内部字符串排序方法规则有关;
(2)setUp运行通过,无论测试用例执行成功与否,tearDown方法都会运行;
(3)setUp方法运行不过,则停止运行;
3.官网case-自定义测试套件
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#@File:test.py
#@Date:2020-07-2012:43
#@Last Modify: 2020-07-2012:43
#@Author:xxx(xxx@xxx.com)
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
def suite():
suite = unittest.TestSuit()
suite.addTest(TestStringMethods("test_isupper"))
suite.addTest(TestStringMethods("test_split"))
suite.addTest(TestStringMethods("test_upper"))
return suite
if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(suite())
4.unittest什么时候报Error,什么时候报Fail?
当代码语法错误时,报Error;
当用例执行错误,不符预期时,报Fail;
5.unittest是用来干什么的?
unittest是用来管理测试用例的;
如何给测试用例起名字?创建测试用例名称必须以test_开始;
unittest在运行之前,会读取整个类中的所有内容,test_开头的被认为是测试用例,不是test_开头的不被认为测试用例,就不会执行。
unittest中运行顺序是既定的,对运行测试用例的顺序是有固定顺序的。A-Z ,a-z ,0-9
每个测试用例之前都会执行setUp,每个测试用例之后都会执行tearDown
测试套件,可以指定unittest执行测试用例的顺序 ;
6.pycharm问题:
1.当选择interpeter报cannot save settings please modify a different sdk 时:操作,将jdk.table.xml删除后,重启pycharm然后,跟preference中重新选择存在的interpeter即可;
2.console解释器跟pycharm配置中的解释器能够对应起来即可:才不会报ImportError: No module named selenium
6.attr标签:
python nose测试框架全面介绍五--attr介绍 - Believer007 - 博客园
二、pytest
Pytest系列(16)- 分布式测试插件之pytest-xdist的详细使用 - 小菠萝测试笔记 - 博客园
allure报告:
pytest + allure的安装及使用 - cherry_ning - 博客园
python自动化之使用allure生成测试报告 - 尘世风 - 博客园
PYTEST_CURRENT_TEST
环境变量:Basic patterns and examples — pytest documentation
setup和teardown等执行顺序:Pytest學習(三) - setup和teardown的使用 | IT人
Pytest学习(一)- 入门及基础 :Pytest学习(一)- 入门及基础 - 久曲健 - 博客园
pytest系列:测试高级进阶技能系列 - Pytest - 随笔分类 - 小菠萝测试笔记 - 博客园
pytest-xdist分布式1:https://www.cnblogs.com/poloyy/p/12703290.html
pytest-xdist分布式2:Pytest系列(16)- 分布式测试插件之pytest-xdist的详细使用
三、pytest装饰器
Pytest系列(10)-pytest.mark.usefixtures详解 - 知乎
@pytest.fixture(scope="作用范围", name="xxxx")
@pytest.mark.parametrize('参数名', [参数值], indirect=True)
@pytest.mark.usefixtures('fixture名字')# 放类上面做装饰器,则表示每个case都会执行该fixture
pytest系列(三) - fixture 的多样玩法 - 简---- - 博客园
步骤:
先用@pytest.fixture定义函数
再用@pytest.fixture定义的函数:
pytest文档17-fixture之autouse=True - 上海-悠悠 - 博客园
四、通过request获取模块及文件中的属性
Pytest----fixture高级应用-阿里云开发者社区
redrose2100_高分内容_社区达人页_阿里云开发者社区
【pytest官方文档】解读- 如何自定义mark标记,并将测试用例的数据传递给fixture函数 - 把苹果咬哭的测试笔记 - 博客园