pyunit擴充套件 根據標籤自動選擇需要執行的用例

2021-06-23 05:14:56 字數 1611 閱讀 2838

一文中介紹了通過配置檔案集中定義需要執行的用例。

但是靜態的定義並不方便,比如新增用例要加入到用例執行列表中,環境的變化要調整用例......

通過標籤來定義用例的執行屬性,讓pyunit在執行時動態選擇用例來得更加靈活:

#rules in this run

#use :: to be replaced in logical formula

rule = '(none::) or (not (1::) and ((2::) or ("three"::)))'

def matchrule(tags):

if isinstance(tags, tuple):

matchformula = rule.replace('::', ' in ' + str(tags))

elif none == tags:

matchformula = rule.replace('::', ' == none')

elif isinstance(tags, str):

matchformula = rule.replace('::', ' == "' + tags + '"')

else:

matchformula = rule.replace('::', ' == ' + str(tags))

#log.d(matchformula)

return eval(matchformula)

def tag(tags = none):

def tag_func(func):

def _(*args, **kwds):

if matchrule(tags):

func(*args, **kwds)

else:

args[0].skiptest(tags)

return _

return tag_func

class test1(testcase):

@tag() #match none

def testaaa(self):

print 'aaa'

@tag(1) #not match

def testbbb(self):

print 'bbb'

@tag(2) #match 2

def testccc(self):

print 'ccc'

class test2(testcase):

@tag((1, 2)) #not match 1

def testddd(self):

print 'ddd'

@tag((2, 3)) #match 2

def testeee(self):

print 'eee'

@tag((4, "three")) #match three

def testfff(self):

print 'fff'

執行結果如下:

aaa.sccc

.seee

.fff

.--------------

ran 6 tests in

ok (skipped=2)

跳過了testbbb和testddd

display標籤擴充套件 根據表頭控制列寬

部落格 網路硬碟 display標籤 displaytag 對於 寬度的控制不是很智慧型,因此有了通過包裝器來擴充套件其功能的想法。最終實現的功能就是 根據表頭標題的寬度,來自動分配表列的寬度,提供兩種模式 字元寬度模式 使用em 及百分比模式,標籤中指定headerclass nosize 的時候...

python 根據標籤名獲取標籤內容

import re import json import requests from bs4 import beautifulsoup import lxml.html from lxml import etree result requests.get with open 123.html wb ...

根據使用者標籤推送內容

首先說一下我們的推送流程吧。我們的推送不是實時的主動的推送給使用者,而是使用者登入後 重新整理頁面 以調介面的方式實時的拉取內容。先上圖 用uml 釋下上面標籤的含義 由於推送標籤具有層級性,同一分支的同一層級是或的關係,如產品使用者,營銷夥伴和金蝶員工是或的關係 產品使用者和使用者角色是 的關係 ...