美文网首页
[接口测试_B] 01 接口测试环境搭建

[接口测试_B] 01 接口测试环境搭建

作者: 乐大爷L | 来源:发表于2018-03-19 08:46 被阅读246次

    学习使用python语言及其相关的库进行接口测试,首先搭建学习过程中使用的测试环境。为了保证环境的独立性,学习过程中相关的库都下载在对应的虚拟环境中。


    【环境信息】

    • Windows 7_x64
    • visual studio code
    • python 3.6
    • git
    • virtualenv
    • pytest
    • requests

    1.安装visual studio code 和python

    visual studio code下载地址:https://code.visualstudio.com/docs/?dv=win
    python下载地址:https://www.python.org/downloads/release/python-364/

    2.git下载和安装

    1. 下载地址:https://git-scm.com/
    2. 打开git bash 配置个人用户信息,包括用户名和邮箱(在github上注册的用户名和邮箱哈
    $ git version # 查看git版本
    $ git config --global user.name "yourname"  # 把yourname设置为你的github用户名
    $ git config --global user.email youremail  # 把youremail设置为你github注册时的邮箱
    $ ssh-keygen -t rsa -C "youremail"  # 把youremail设置为你github注册时的邮箱,生成ssh key公钥,用于github验证
    

    3.在github上添加生成的公钥,登录github打开settings->SSH and GPG key 添加生成的ssh key 公钥,公钥若生成在默认目录下,可用命令cat ~/.ssh/id_rsa.pub查看:

    添加ssh key
    1. 验证git连接是否成功:在github上新建一个仓库 ,执行git clone操作:
    $ git clone https://github.com/catleer/python_interface_test
    Cloning into 'python_interface_test'...
    warning: You appear to have cloned an empty repository.
    

    3.安装virtualenv

    virtualenv可以构造一个独立的环境,使不同工程之间使用的包不会互斥。同时,也便于环境的移植。

    1. windows下安装:
    python -m pip install virtualenv
    
    1. 创建虚拟环境
    # virtualenv 目录名
    virtualenv python_interface_base
    
    1. 激活虚拟环境,windows下激活virtualenv的环境不需要使用source命令,直接执行虚拟环境中scripts目录下的activate即可:
    f:\python_interface_test\python_interface_test>python_interface_base\Scripts\activate
    
    (python_interface_base) f:\python_interface_test\python_interface_test>
    
    1. 退出虚拟环境,执行Scripts目录下的deactivate:
    (python_interface_base) f:\python_interface_test\python_interface_test>python_interface_base\Scripts\deactivate.bat
    f:\python_interface_test\python_interface_test>
    

    4. 在虚拟环境中安装pytest和requests

    1. 激活要工作的虚拟环境:
    f:\python_interface_test\python_interface_test>python_interface_base\Scripts\activate
    
    (python_interface_base) f:\python_interface_test\python_interface_test>
    
    1. 安装pytest和requests:
    pip install pytest
    pip install requests
    
    1. 查看安装的包的版本,将包名及版本信息导出:
    pip freeze > is_installed_package.txt
    
    attrs==17.4.0
    certifi==2018.1.18
    chardet==3.0.4
    colorama==0.3.9
    idna==2.6
    pluggy==0.6.0
    py==1.5.2
    pytest==3.4.2
    requests==2.18.4
    six==1.11.0
    urllib3==1.22
    

    5.环境运行示例

    1. 打开Visual studio code,打开工作文件夹(从github上clone下来的文件目录),激活虚拟环境:


      运行示例
    2. 测试在虚拟环境下,pytest和requests能否正常工作;

    3.查看visual studio code中能否提交至git本地仓库;


    image.png
    1. 提交更改后的代码至github,需要先进入github中clone下来的文件目录:
    # 添加文件到缓存
    git add 文件名  # 由于在visual studio上暂存了文件,则该步可以不在git bash中执行;
    
    # 将缓存文件添加到仓库
    git commit -m "日志说明“  # 在visual studio code中执行了提交操作,则该步可以不在gitbash中执行;
    
    # 推送至github
    git push  # 会提示输入用户名密码
    
    1. 登录github查看是否推送成功;

    6.结束本次工作,去激活虚拟环境:

    (python_interface_base) F:\python_interface_test>python_interface_base\Scripts\deactivate.bat
    

    相关文章

      网友评论

          本文标题:[接口测试_B] 01 接口测试环境搭建

          本文链接:https://www.haomeiwen.com/subject/fojhqftx.html