ReportPortal 在python下的應用介紹之----python各框架整合

接上一篇,裝完之後,需要對接我們現有的自動化測試。就Python而言,有幾種框架可以直接使用,這裏介紹一下

首先,我們需要了解這是agent server模式,所以server上認證信息需要拿到。按這種方法拿:

登錄進系統後,輸入對應的地址:http://xxx/ui/#user-profile,有對應的token信息:

 

 

 

一、Nose

步驟:

先安裝插件

pip install nose-reportportal

我們拿下面這段簡單代碼來嘗試

# coding = utf-8

# author:huzq
import logging
log = logging.getLogger(__name__)
class Testclass:

    def __init__(self):

        pass

    def setup(self):

        print('start')

    def teardown(self):

        print('stop')

    def testfunc1(self):
        """dafdfdfd"""
        log.info("bbbbd")

        print('this is case1')

    def testfunc2(self):
        log.info("bbbbd")
        print('this is case2')

    def testfunc3(self):
        log.info("bbbbd")

        print('this is case3')
View Code

怎麼運行呢?

兩種方法:

1.文件形式

新建文件rp.ini,如下內容:

[base]
rp_uuid = fb586627-32be-47dd-93c1-678873458a5f
rp_endpoint = http://192.168.1.10:8080
rp_project = user_personal
rp_launch = AnyLaunchName
rp_launch_tags = Nose
rp_launch_description = Smoke test

不過對應的信息需要修改

運行:

nosetests xxx.py --with-reportportal --rp-config-file rp.ini

2.命令行形式

直接下面的命令:

nosetests xxx.py --with-reportportal --rp_uuid=xxxx rp_endpoint=http://xxx --rp_project=xxxx --rp_launch=xxx
--rp-config-file rp.ini

但這個時候,你可能會遇到下面這個問題:

 

 怎麼辦呢?直接給出解決方案吧:

找到對應python的site-packages中的nose_reportportal文件夾,修改service.py文件

修改第116行爲下面這個樣子:

"parameters": None,

再次運行,問題可以解決。

 

二、pytest

安裝:

pip install pytest-reportportal

添加配置 文件config.cfg

[tool:pytest]
rp_uuid = 55466cae-8588-452c-9400-9ce4c5960e98
rp_endpoint = https://xxxx
rp_project = user
rp_launch = default_TEST_EXAMPLE
rp_launch_attributes = 'PyTest' 'Smoke'
rp_launch_description = 'Smoke test'
rp_ignore_errors = True
rp_ignore_attributes = 'xfail' 'usefixture'

對應的內容要修改

運行:

pytest xxxx.py --reportportal config.cfg

三、其它

其它的就不詳細介紹,大同小異

比如RF

pip install robotframework-reportportal

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章