1. 程式人生 > >httprunner-1-linux下搭建hrun(上)

httprunner-1-linux下搭建hrun(上)

前言

相信不少小夥伴對開源專案 httprunner 都很感興趣,我們來看下它的有哪些特點吧:

  • 專案管理:新增專案、列表展示及相關操作,支援用例批量上傳(標準化的HttpRunner json和yaml用例指令碼)
  • 模組管理:為專案新增模組,用例和配置都歸屬於module,module和project支援同步和非同步方式
  • 用例管理:分為新增config與test子功能,config定義全部變數和request等相關資訊 request可以為公共引數和請求頭,也可定義全部變數
  • 場景管理:可以動態載入可引用的用例,跨專案、跨模快,依賴用例列表支援拖拽排序和刪除
  • 執行方式:可單個test,單個module,單個project,也可選擇多個批量執行,支援自定義測試計劃,執行時可以靈活選擇配置和環境,
  • 分佈執行:單個用例和批量執行結果會直接在前端展示,模組和專案執行可選擇為同步或者非同步方式,
  • 環境管理:可新增執行環境,執行用例時可以一鍵切換環境
  • 報告檢視:所有非同步執行的用例均可線上檢視報告,可自主命名,為空預設時間戳儲存,
  • 定時任務:可設定定時任務,遵循crontab表示式,可線上開啟、關閉,完畢後支援郵件通知
  • 持續整合:jenkins對接,開發中。。。

特點還不錯,但是目前此專案已停止維護,作為測開的我們在此基於hrun(httprunner)進行二次開發是個很不錯的選擇!

一、預備工作

  1.阿里雲伺服器,注意:如果重置密碼後,需要重啟伺服器;

  2.注意開放所用到的埠,小編直接暴力開放了全部埠;

  3.遠端連線伺服器工具:Xshell、SecureCRTPortable(小編用的就是這個)

  我們hrun所需環境:python3 + mysql5.7(官方推薦)+ Django2 + httprunner==1.58

二、搭建python3環境

  1.安裝環境依賴包,避免後面少出現包的問題(之前試過沒執行,導致沒有pip3)

  命令:yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel mysql-devel

[root@iZbp19lugf22zbsubsf1y6Z home]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel mysql-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 5.3 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): extras/7/x86_64/primary_db | 153 kB 00:00:00
(2/4): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(3/4): updates/7/x86_64/primary_db | 2.8 MB 00:00:00
(4/4): epel/x86_64/primary_db | 6.9 MB 00:00:00
Package zlib-devel-1.2.7-18.el7.x86_64 already installed and latest version
Package bzip2-devel-1.0.6-13.el7.x86_64 already installed and latest version
Package 1:openssl-devel-1.0.2k-19.el7.x86_64 already installed and latest version
Package ncurses-devel-5.9-14.20130511.el7_4.x86_64 already installed and latest version
Package sqlite-devel-3.7.17-8.el7.x86_64 already installed and latest version
Package readline-devel-6.2-11.el7.x86_64 already installed and latest version
Package 1:tk-devel-8.5.13-6.el7.x86_64 already installed and latest version
Package gdbm-devel-1.10-8.el7.x86_64 already installed and latest version
Package libdb4-devel-4.8.30-13.el7.x86_64 already installed and latest version
Package 14:libpcap-devel-1.5.3-11.el7.x86_64 already installed and latest version
Package xz-devel-5.2.2-1.el7.x86_64 already installed and latest version
Package 1:mariadb-devel-5.5.64-1.el7.x86_64 already installed and latest version
Nothing to do

 

  2.版本你需要安裝哪個版本就下載哪個python3以上就行,推薦3.6.5,linux上下載加上字尾就行了。

  python檢視版本地址:https://www.python.org/ftp/python/  小編是用獨有的wget下載3.6.5(因為我已經安裝了),可能下載時間有點長,當然也可以在本地下載好上傳至伺服器上,如果喜歡用shell指令碼一鍵安裝的朋友還是用wget下載給力:wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

[root@iZbp19lugf22zbsubsf1y6Z home]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
--2019-10-27 14:43:39-- https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
Resolving www.python.org (www.python.org)... 151.101.228.223, 2a04:4e42:36::223
Connecting to www.python.org (www.python.org)|151.101.228.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22994617 (22M) [application/octet-stream]
Saving to: ‘Python-3.6.5.tgz’

100%[===================================================================================================================================================================================================>] 22,994,617 13.4KB/s in 29m 59s

2019-10-27 15:13:39 (12.5 KB/s) - ‘Python-3.6.5.tgz’ saved [22994617/22994617]

  3.在此包目錄下解壓tgz包,輸入:tar -xvf Python-3.6.5.tgz

[root@iZbp19lugf22zbsubsf1y6Z home]# tar -xvf Python-3.6.5.tgz

Python-3.6.5/Lib/test/test_wait3.py
Python-3.6.5/Lib/test/test_ordered_dict.py
Python-3.6.5/Lib/test/test_exception_variations.py
Python-3.6.5/Lib/test/test_argparse.py
Python-3.6.5/Lib/test/test_multibytecodec.py
Python-3.6.5/Lib/test/test_strftime.py
Python-3.6.5/Lib/test/tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt
Python-3.6.5/Lib/test/test_ipaddress.py
Python-3.6.5/Lib/test/test_mmap.py
Python-3.6.5/Lib/test/test_ftplib.py
Python-3.6.5/Lib/test/test_selectors.py
Python-3.6.5/Lib/test/test_operator.py
Python-3.6.5/Lib/test/badsyntax_future10.py
Python-3.6.5/Lib/test/test_decimal.py
Python-3.6.5/Lib/test/test_popen.py
Python-3.6.5/Lib/test/test_genexps.py
Python-3.6.5/Lib/test/test_stat.py
Python-3.6.5/Lib/test/datetimetester.py
Python-3.6.5/Lib/test/test_socketserver.py
Python-3.6.5/Lib/test/test_codecmaps_hk.py
Python-3.6.5/Lib/test/curses_tests.py
Python-3.6.5/Lib/test/test_decorators.py
Python-3.6.5/Lib/test/test_pyclbr.py

...

  4.在Python-3.6.5目錄下指定安裝目錄:./configure --prefix=/home/python365

[root@iZbp19lugf22zbsubsf1y6Z Python-3.6.5]# ./configure --prefix=/home/python365

checking stropts.h usability... no
checking stropts.h presence... no
checking for stropts.h... no
checking termios.h usability... yes
checking termios.h presence... yes
checking for termios.h... yes
checking for unistd.h... (cached) yes
checking utime.h usability... yes
checking utime.h presence... yes
checking for utime.h... yes
checking poll.h usability... yes
checking poll.h presence... yes
checking for poll.h... yes
checking sys/devpoll.h usability... no
checking sys/devpoll.h presence... no

...

  5.在Python-3.6.5目錄下編譯輸入:make    編譯時間有點長,等幾分鐘完成後再安裝,輸入:make install

[root@iZbp19lugf22zbsubsf1y6Z Python-3.6.5]# make
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I. -I./Include -DPy_BUILD_CORE -o Programs/python.o ./Programs/python.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I. -I./Include -DPy_BUILD_CORE -o Parser/parser.o Parser/parser.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I. -I./Include -DPy_BUILD_CORE -o Parser/bitset.o Parser/bitset.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I. -I./Include -DPy_BUILD_CORE -o

...省略

[root@iZbp19lugf22zbsubsf1y6Z Python-3.6.5]# make install
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I. -I./Include -DPy_BUILD_CORE -o Objects/listobject.o Objects/listobject.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I. -I./Include -DPy_BUILD_CORE -o Objects/longobject.o Objects/longobject.

...省略

  6.設定python365和pip365的軟連結,這裡因為自帶了python2.7已有類同的軟連結,我們要另設定為 python365 和 pip365,可以隨便命名:

  ln -s /home/python365/bin/python3.6 /usr/bin/python365

  ln -s /home/python365/bin/pip3 /usr/bin/pip365

  注意:我們上面的指定了安裝目錄為:/home/python365,然而我們設定軟連結也是在/home/python365下面。

[root@iZbp19lugf22zbsubsf1y6Z bin]# ln -s /home/python365/bin/python3.6 /usr/bin/python365
[root@iZbp19lugf22zbsubsf1y6Z bin]# ln -s /home/python365/bin/pip3 /usr/bin/pip365
[root@iZbp19lugf22zbsubsf1y6Z bin]#

  7.驗證 python 的版本輸入:python365 -V

[root@iZbp19lugf22zbsubsf1y6Z bin]# python365 -V
Python 3.6.5
[root@iZbp19lugf22zbsubsf1y6Z bin]# python
Python 2.7.5 (default, Jul 13 2018, 13:06:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

  8.驗證 pip365 的版本.

[root@iZbp19lugf22zbsubsf1y6Z bin]# pip365 -V
pip 9.0.3 from /home/python365/lib/python3.6/site-packages (python 3.6)

  9.上面看到pip365版本為9.0.3,我們將pip365也升級至最新版輸入:pip365 install --upgrade pip

[root@iZbp19lugf22zbsubsf1y6Z bin]# pip365 install --upgrade pip
Collecting pip
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 44.6MB/s
Installing collected packages: pip
Found existing installation: pip 9.0.3
Uninstalling pip-9.0.3:
Successfully uninstalled pip-9.0.3
Successfully installed pip-19.3.1

  10.再來檢視一下pip365的版本已為最新版。

[root@iZbp19lugf22zbsubsf1y6Z bin]# pip365 -V
pip 19.3.1 from /home/python365/lib/python3.6/site-packages/pip (python 3.6)

這樣就完成了python3的安裝了,如遇到有問題歡迎留言交流!!!

&n