当前位置:网站首页>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)
边栏推荐
- Based on STM32F103 - matrix key + serial port printing
- 【TcaplusDB知识库】TcaplusDB-tcapsvrmgr工具介绍(一)
- Internal register type
- 内部寄存器类型
- 基于三维GIS技术的行业发展及研究现状
- Books + videos + learning notes + skill improvement resource library, interview must ask
- Pulsar producer
- CPU的分支预测
- 即构推出行业首个数据流录制PaaS方案,低成本复刻头部大厂录制能力
- 基于STM32F103——AS608指纹模块+串口打印
猜你喜欢

10、DCN 介绍

14. Notes on using border decorator of WPF

Auto. JS floating window centered

Text error correction -- crisp model

Based on STM32F103 - DS1302 date time + serial port printing
![[tcaplusdb knowledge base] Introduction to tcaplusdb tcapulogmgr tool (I)](/img/46/e4a85bffa4b135fcd9a8923e10f69f.png)
[tcaplusdb knowledge base] Introduction to tcaplusdb tcapulogmgr tool (I)
![[tcapulusdb knowledge base] Introduction to tcapulusdb table data caching](/img/8b/96ecf2d9c97b3dd2cabe5ca68c3414.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb table data caching

Pulsar consumer

Seccloud and trend technology jointly release the overall solution of container cloud platform and GPU resource pooling
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (III)](/img/46/e4a85bffa4b135fcd9a8923e10f69f.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (III)
随机推荐
面试突击56:聚簇索引和非聚簇索引有什么区别?
[tcapulusdb knowledge base] Introduction to tcapulusdb analytical text export
The industry-leading interface component package devaxpress officially released v21.2.8 in June
智能客服系统框架rasa
The answer to the subject of Municipal Administration of the second construction company in 2022 has been provided. Please keep it
杜邦分析法剖析:居然之家新零售集团股份有限公司企业财务分析
web開發項目,web單頁開發
Committed to R & D and manufacturing of ultra surface photonic chip products, Shanhe optoelectronics completed a round of pre-A financing of tens of millions of yuan
内部寄存器类型
002. Torchserve calls the official library model
陈宏智:字节跳动自研万亿级图数据库ByteGraph及其应用与挑战
Web development video tutorial, web development teaching
二建资格后审没通过怎么办?这篇文章告诉你
加载中旋转沙漏
【真相】大厂招人不怕花钱的原因竟然是。。。
Wallys/Network_Card/DR-NAS26/AR9223/2x2 MIMO
Based on STM32F103 - matrix key + serial port printing
燃油方案和产品业务建模
Problems encountered in using the Pluto table of the flutter plug-in
Based on STM32F103 - as608 fingerprint module + serial port printing