1.pytest-html报告
安装:pip install pytest-html==2.1.1
运行:pytest 文件名 –html=路径/文件名称
2.pytest-ordering:控制函数执行的顺序
安装:pip install pytest-ordering
@pytest.mark.run(order=X):用于标记被测试函数
根据order传入的参数解决运行顺序
order值全为正数或全为负数时,运行顺序:值越小,优先级越高
当有正数和负数的同事时,正数优先。
[En]
When colleagues with positive and negative numbers exist, positive numbers have high priority.
2.pytest-rerunfailures
在配置行的命令参数中增加 –reruns n,如:
pytest -s 文件名 –reruns 3 –reruns-delay 1(失败重跑次数3,失败后延迟一秒)
3.跳过测试函数、
在需要跳过的脚本标记:@pytest.mark.skip(reason=”原因”)
4.预期失败
应用场景:尚未实现或修复的错误将导致预期的失败;预期的情况将失败
[En]
Application scenario: errors that have not yet been implemented or repaired will result in expected failure; a desired situation will fail
@pytest.mark.xfail()
class Test_xfail:
@pytest.mark.xfail()
def test_cass01(self):
print("失败")
assert 1==2
def test_cass02(self):
assert 1==1
5.数据参数化
应用场景:如果您在登录时需要多个帐户名和密码,您可以使用参数化来实现此功能。
[En]
Application scenario: if you need multiple account names and passwords when logging in, you can use parameterization to achieve this function.
@pytest.mark.parametrize(参数名,参数对应值)
参数名:为字符串
参数对应值:为列表
单个参数的传递:
class Test_per:
@pytest.mark.parametrize("age",[1,44,23,34])
def test_a(self,age):
print(age)
多个参数的传递:
class Test_per1:
@pytest.mark.parametrize(("name","age"),[("nini",12),("qq",1),("as",34)])
def test_a(self,name,age):
print(name,age)
6.pytest-fixture
应用场景:完成预置处理和重复操作
[En]
Application scenario: complete preset processing and repetitive operations
@pytest.fixture
如:登录,用户a需要先登录,用户b不需要登录,用户c需要登录
class Test_fixture:
@pytest.fixture()
def login(self):
print("登录操作")
uname="lulu"
return uname
def test_a(self,login):
print(f"test_a{login}")
def test_b(self):
print("不需要登录操作")
def test_c(self,login):
print(f"test_c{login}")
Original: https://blog.csdn.net/weixin_42684108/article/details/125317879
Author: 小杰杰的学习日常
Title: pytest学习(二)
相关阅读
Title: 移植第一个django项目
目录
搭建pvenv
git clone https://gitee.com/feiyujun/pyenv.git ~/.pyenv
sudo vim /etc/profile
export PYENV_ROOT="/root/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
$ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev
apt-get install -y openssl
apt-get install -y libssl-dev
安装miniconda
wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod 777 Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh
- Do you accept the license terms? [yes|no]———->yes
- Miniconda3 will now be installed into this location:xxxx 这个地址需要记忆,一般情况下是~/miniconda3
- Do you wish the installer to initialize Miniconda3 by running conda init? [yes|no]—–>no
echo "export PATH="/home/gaoxiang/miniconda3/bin:"$PATH" >> ~/.bashrc
source ~/.bashrc
安装python3.5
方案一
apt-get install software-properties-common
方案二
- 安装python
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar -xvzf Python-3.5.2.tgz
cd Python-3.5.2
./configure --prefix=/usr/local/python35
make -j4
make install
cp /usr/local/python35/bin/python3.5 /usr/bin
- 安装pip
curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
python3.5 get-pip.py
cp /usr/local/python35/bin/pip3.5 /usr/bin
note: 安装pip时候可能会出错,可以前往系统已安装的python lib目录下拷贝一个文件过来,下例是我这边的文件路径
cp /usr/lib/python3/dist-packages/lsb_release.py /usr/local/python35/lib/python3.5/
安装依赖包
pip install -r requirements.txt
pip install -r requests.txt
安装mysql
apt-install install -y mysql-server
在mysqld.cof中设置 bind-address = 0.0.0.0
vim /etc/mysql/mysql.conf.d/mysqld.cnf
service mysql restart
运行
python3.5 mamger.py runserver
Original: https://blog.csdn.net/qq_34954047/article/details/123538391
Author: 域中四大
Title: 移植第一个django项目
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/338534/
转载文章受原作者版权保护。转载请注明原作者出处!