当前位置:网站首页>Selenium3 automatic test practice (5)
Selenium3 automatic test practice (5)
2022-06-13 12:14:00 【Sixiaoyou】
Catalog
1.Python A simple example
import pytest
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
if __name__ == '__main__':
pytest.main()
2. Assertion
# function : Used to calculate a And b Additive sum
def add(a, b):
return a + b
# function : Used to judge prime numbers
def is_prime(n):
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
# Test equality
def test_add_1():
assert add(3, 4) == 7
# The tests are not equal
def test_add_2():
assert add(17, 22) != 50
# Test less than or equal to
def test_add_3():
assert add(17, 22) <= 50
# Test greater than or equal to
def test_add_4():
assert add(17, 22) >= 38
# The test contains
def test_in():
a = "hello"
b = "he"
assert b in a
# Test does not contain
def test_not_in():
a = "hello"
b = "hi"
assert b not in a
# Judge whether it is True
def test_true_1():
assert is_prime(13)
# Judge whether it is True
def test_true_2():
assert is_prime(7) is True
# Judge whether it is not True
def test_true_3():
assert not is_prime(4)
# Judge whether it is not True
def test_true_4():
assert is_prime(6) is not True
# Judge whether it is False
def test_fasle_1():
assert is_prime(8) is False
3.Fixture
import pytest
def multiply(a,b):
return a * b
def setup_module(module):
print("setup_module===================>")
def teardown_module(module):
print("teardown_module==================>")
def setup_function(function):
print("setup_function=================>")
def teardown_function(function):
print("teardown_function===============>")
def setup():
print("setup==================>")
def teardown():
print("teardown==================>")
# ============== The test case ==================
def test_multiply_3_4():
print('test_numbers_3_4')
assert multiply(3,4) == 12
def test_multiply_a_3():
print('test_strings_a_3')
assert multiply('a',3) == 'aaa'
# Function function
def multiply(a, b):
return a * b
class TestMultiply:
# ======Fixture======
@classmethod
def setup_class(cls):
print("setup_class=============>")
@classmethod
def teardown_class(cls):
print("teardown_class===============>")
def setup_method(self,method):
print("setup_method-------->>")
def teardown_method(self,method):
print("teardown_method-->>")
def setup(self):
print("setup----->")
def teardown(self):
print("teardown----->")
# =========== The test case ===========
def test_numbers_5_6(self):
print('test_numbers_5_6')
assert multiply(5,6) == 30
def test_strings_b_2(self):
print('test_strings_b_2')
assert multiply('b',2) == 'bb'
4. A parameterized
import pytest
import math
#pytest A parameterized
@pytest.mark.parametrize(
"base, exponent, expected",
[(2, 2, 4),
(2, 3, 8),
(1, 9, 1),
(0, 9, 0)],
ids = ["case1","case2","case3","case4"]
)
def test_pow(base,exponent,expected):
assert math.pow(base, exponent) == expected
5.conftest.py
import pytest
@pytest.fixture()
def test_url():
return "http://www.baidu.com"
def test_baidu(test_url):
print(test_url)
6.pytest-rerunfailures
pytest -v test_rerunfailures.py --reruns 3
def test_fail_rerun():
assert 2 + 2 == 5
7.pytest-parallel
pytest -q test_parallel.py --test-per-worker auto
from time import sleep
def test_01():
sleep(3)
def test_02():
sleep(5)
def test_03():
sleep(6)
边栏推荐
猜你喜欢
陈宏智:字节跳动自研万亿级图数据库ByteGraph及其应用与挑战
产品故事|你所不知道的语雀画板
2022年二建《市政》科目答案已出,请收好
web開發項目,web單頁開發
机器学习(二)—逻辑回归理论与代码详解
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)
MCDF Experiment 2
The most complete network, including interview questions + Answers
Web development project, web single page development
14、wpf之Border装饰器使用小记
随机推荐
14. Notes on using border decorator of WPF
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)
[management knowledge] risk of "risk register"
Pulsar producer
机器学习(三)— LDA(线性判别分析)理论与代码详解
基于STM32F103——矩阵按键+串口打印
面试题 Mysql 数据库
基於STM32F103+AS608指紋模塊+4X4矩陣按鍵+SIM900A發短信——智能門禁卡系統
【Scala】Scala常用代码库—六大特征与引用
web开发者,web开发后台开发
致力超表面光子芯片产品研发与制造,山河光电完成数千万元Pre-A轮融资
IDEA 使用
5 LockSupport与线程中断
Fuel scheme and product business modeling
004、torchserve 调用LR二分类预测
fitfi运动赚钱链游系统开发模式详情
书籍+视频+学习笔记+技能提升资源库,面试必问
How to use dataX to update the data in the downstream Oracle database with the update semantics?
一文说清楚ToB SaaS系统的权限管理的设计
Kubernetes问题整理