jianbing / utx Goto Github PK
View Code? Open in Web Editor NEW对Python unittest的功能进行了扩展(用例排序,分组,数据驱动,可视化报告等)
License: MIT License
对Python unittest的功能进行了扩展(用例排序,分组,数据驱动,可视化报告等)
License: MIT License
我搜索unittest 用例排序找到了你的代码,但是我发现一个问题,就是在获取class的函数属性的时候,其实是在从字典里拿数据,字典是无序的,那你拿到的函数根本不是按照添加的顺序排列的,所以你做的重命名也是在对本身顺序错误的列表进行重命名啊,
问题在于这里funcs_dict,这是一个字典,你迭代一个字典,每次的结果都是不一样的,这不是列表
@staticmethod
def filter_test_case(funcs_dict):
funcs = dict()
cases = dict()
for i in funcs_dict:
if i.startswith("test_"):
cases[i] = funcs_dict[i]
else:
funcs[i] = funcs_dict[i]
return funcs, cases
我自己单纯只提供排序的元类,如下,也是有相同的问题,不知道这个怎么处理
class Meta(type):
def __new__(cls, name, parents, attrs):
LONG = 4
id = 1
_attrs = {}
for k, v in attrs.items():
if k.startswith('test_'):
id_str = str(id).zfill(LONG)
_k = k.replace('test_', 'test_{}_'.format(id_str))
_attrs[_k] = v
id += 1
else:
_attrs[k] = v
return type.__new__(cls, name, parents, _attrs)
attrs.items() 是把一个无序的字典变成的列表,这个列表迭代也无法得到按照函数添加的顺序排序,不知道你是怎么做到可以按照添加的顺序来排序的?反正我看代码没有看出来
_logger_handler.setFormatter(logging.Formatter('%(asctime)s %(message)s' + '\n'))
建议增加换行
\utx-0.0.2-py3.6.egg\utx\log.py
line:13
运行报错如下
File "/Users/ssfanli/Myfolder/pyproj/work/YSPCheckListAndroid/case/test_1_home_page.py", line 17, in <module>
class HomePageTest(BaseUnittest):
File "/Users/ssfanli/Myfolder/pyproj/work/YSPCheckListAndroid/utx/core.py", line 220, in __new__
setattr(test_case, CASE_TAG_FLAG, {Tag.ALL}) # 没有指定tag的用例,默认带有tag:ALL
AttributeError: 'NoneType' object has no attribute '__case_tag__'
class HomePageTest(BaseUnittest):
def setUp(self) -> None:
self.hp = HomePage(self.d)
def tearDown(self) -> None:
self.hp.auto_back()
@tag(Tag.SMOKE)
def test_recommend(self):
......
Traceback (most recent call last):
File "", line 1, in
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/lincanyi/Project/interface-tools/lxtx/case/debugCase.py", line 13, in
runner.run_test(report_title='接口自动化测试报告')
File "/Users/lincanyi/Project/interface-tools/venv/lib/python3.8/site-packages/utx-0.0.7-py3.8.egg/utx/runner.py", line 222, in run_test
_TestRunner(report_dir=report_dir, report_title=report_title).run(suite)
File "/Users/lincanyi/Project/interface-tools/venv/lib/python3.8/site-packages/utx-0.0.7-py3.8.egg/utx/runner.py", line 118, in run
style_1.build_report(file_path, result_data)
File "/Users/lincanyi/Project/interface-tools/venv/lib/python3.8/site-packages/utx-0.0.7-py3.8.egg/utx/report/style_1.py", line 377, in build_report
test_pass_per="{:.2%}".format(data['testPass'] / data['testAll']),
ZeroDivisionError: division by zero
py文件不以开头test开头会报0错误
2019-10-19 16:35:17,300 WARNING doctest.test_skip没有用例描述
2019-10-19 16:35:17,319 WARNING test_baidu.test_timedistance_v0没有用例描述
2019-10-19 16:35:17,319 INFO 开始测试,用例数量总共10个,跳过0个,实际运行10个
2019-10-19 16:35:17,420 INFO start to test test_baidu.test_timedistance_v0 (2/10)
2019-10-19 16:35:17,519 INFO start to test test_baidu.test_timedistance_v0 (3/10)
2019-10-19 16:35:17,619 INFO start to test test_tattle.test_get_battle_reward (9/10)
2019-10-19 16:35:17,720 INFO start to test test_tattle.test_get_battle_reward (10/10)
2019-10-19 16:35:17,819 INFO start to test test_tattle.test_bless (4/10)
2019-10-19 16:35:17,920 INFO start to test test_tattle.test_bless (5/10)
2019-10-19 16:35:18,019 INFO start to test test_tattle.test_receive_bless_box (6/10)
2019-10-19 16:35:18,119 INFO start to test test_tattle.test_receive_bless_box (7/10)
2019-10-19 16:35:18,220 INFO start to test test_tattle.test_receive_bless_box (8/10)
2019-10-19 16:35:18,220 INFO Time Elapsed: 0:00:00.900000
真实情况是用例只有9个,统计结果是10个,index也有点问题,不是从第1个开始计数
python setup.py install
提示
python: can't open file 'setup.py': [Errno 2] No such file or directory
其实只想要个排序的功能而已,其它的功能HTMLReport已经做完了
操作就是单个执行unittest中的TestCase
Traceback (most recent call last):
File "C:\Python36\Lib\unittest\case.py", line 59, in testPartExecutor
yield
File "C:\Python36\Lib\unittest\case.py", line 605, in run
testMethod()
File "C:\Python36\Lib\unittest\loader.py", line 34, in testFailure
raise self._exception
File "C:\Python36\Lib\unittest\loader.py", line 168, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: type object 'ReadingProcess' has no attribute 'test_createTask'
2019-07-08 17:12:12,761 INFO 开始测试,用例数量总共3个,跳过0个,实际运行3个
2019-07-08 17:12:12,761 INFO Time Elapsed: 0:00:00.000198
Traceback (most recent call last):
File "/Users/user/app/interface/test-interfaces.git/WORK/AVN_Test/Sample.py", line 84, in
runner.run_test(report_title='接口自动化测试报告')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/utx-0.0.7-py3.7.egg/utx/runner.py", line 222, in run_test
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/utx-0.0.7-py3.7.egg/utx/runner.py", line 118, in run
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/utx-0.0.7-py3.7.egg/utx/report/style_1.py", line 377, in build_report
ZeroDivisionError: division by zero
Process finished with exit code 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.