前提:需要安装pytest和pytest-html(生成html测试报告)
pip install pytest 和 pip install pytest-html



1:命名规则
Pytest单元测试中的类名和方法名必须是以test开头,执行中只能找到test开头的类和方法,比unittest更加严谨
2:Pytest生成自带的html测试报告

运行指定的模块以指定类以指定用例、拆分冒号并生成测试报告
[En]
Run the specified module to specify the class to specify the use case, split the colon, and generate the test report


在浏览器查看案例:
pytest.main([“-x”,”–html=./report.html”,”test_01.py::TestClass::test02″])
“–html=./report.html”:在浏览器里面显示测试用例
“test_01.py::TestClass::test02″:运行指定模块用例
(相当于我执行我test_01这个文件 TestClass这个类 test02这个方法)



测试用例在浏览器中执行成功:
[En]
The test case executed successfully in the browser:


pytest.main(["-x","--html=./report.html","test_01.py::TestClass::test02"])
“-x”作用:



Original: https://blog.csdn.net/Poenet_EN/article/details/120667445
Author: Po_Po_Na
Title: python–单元测试之pytest
相关阅读
Title: plt.plot(),plt.scatter(),plt.legend函数的用法介绍
plt.plot()函数
plt.plot(x, y, format_string, **kwargs)
参数说明 x
X轴数据,列表或数组,可选 y
Y轴数据,列表或数组 format_string
控制曲线的格式字符串,可选 **kwargs
第二组或更多(x,y,format_string),可画多条曲线
format_string
由颜色字符、风格字符、标记字符组成
- 颜色字符
'b'
蓝色'm'
洋红色 magenta'g'
绿色'y'
黄色'r'
红色'k'
黑色'w'
白色'c'
青绿色 cyan'#008000'
RGB某颜色'0.8'
灰度值字符串- 多条曲线不指定颜色时,会自动选择不同颜色
- 风格字符
'‐'
实线'‐‐'
破折线'‐.'
点划线':'
虚线'' ' '
无线条- 标记字符
'.'
点标记','
像素标记(极小点)'o'
实心圈标记'v'
倒三角标记'^'
上三角标记'>'
右三角标记'<'< code> 左三角标记…等等<!--'<-->
**kwargs
: 第二组或更多(x,y,format_string)
color
: 控制颜色, color=’green’
linestyle
: 线条风格, linestyle=’dashed’
marker
: 标记风格, marker=’o’
markerfacecolor
: 标记颜色, markerfacecolor=’blue’
markersize
: 标记尺寸, markersize=20
b = np.arange(5)
plt.plot(b,b*1.0,'g.-',b,b*1.5,'rx',b,b*2.0, 'b')
plt.show()

plt.scatter()函数
plt.scatter()函数用于生成一个scatter散点图。
matplotlib.pyplot.scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, hold=None, **kwargs
参数解释说明x,y表示的是shape大小为(n,)的数组,也就是我们即将绘制散点图的数据点,输入数据。s表示的是大小,是一个标量或者是一个shape大小为(n,)的数组,可选,默认20。c表示的是色彩或颜色序列,可选,默认蓝色’b’。但是c不应该是一个单一的RGB数字,也不应该是一个RGBA的序列,因为不便区分。c可以是一个RGB或RGBA二维行数组。markerMarkerStyle,表示的是标记的样式,可选,默认’o’。cmapColormap,标量或者是一个colormap的名字,cmap仅仅当c是一个浮点数数组的时候才使用。如果没有申明就是image.cmap,可选,默认None。normNormalize,数据亮度在0-1之间,也是只有c是一个浮点数的数组的时候才使用。如果没有申明,就是默认None。vmin,vmax标量,当norm存在的时候忽略。用来进行亮度数据的归一化,可选,默认None。alpha标量,0-1之间,可选,默认None。linewidths标记点的长度,默认None。
例子
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
x=np.random.rand(20)
y=np.random.rand(20)
area=(50*np.random.rand(20))**2
plt.scatter(x,y,s=area,alpha=0.5)
plt.show()

plt.legend()函数
1.设置图例的位置
plt.legend(loc=' ')
2.设置图例字体大小
fontsize : int or float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}
3.设置图例边框及背景
plt.legend(loc='best',frameon=False)
plt.legend(loc='best',edgecolor='blue')
plt.legend(loc='best',facecolor='blue')
4.设置图例标题
legend = plt.legend(["BJ", "SH"], title='Beijing VS Shanghai')
plt.plot(["BJ", "SH"],loc='upper left',title='Beijing VS Shanghai')
5.设置图例名字及对应关系
legend = plt.legend([p1, p2], ["BJ", "SH"])
示例
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0,10,1)
plt.plot(x,x,'r--',x,np.cos(x),'g--',marker='*')
plt.xlabel('row')
plt.ylabel('cow')
plt.legend(["BJ","SH"],loc='upper left',loc='upper left')
plt.show()
运行结果

Original: https://blog.csdn.net/qq_43186282/article/details/121513266
Author: Sunny.T
Title: plt.plot(),plt.scatter(),plt.legend函数的用法介绍
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/338394/
转载文章受原作者版权保护。转载请注明原作者出处!