
python nose setuptools 快速入门
发布日期:2021-05-17 18:23:21
浏览次数:19
分类:精选文章
本文共 2135 字,大约阅读时间需要 7 分钟。
安装依赖并运行测试
安装依赖
安装nose测试框架:
pip3 install nose
安装setuptools:
pip3 install setuptools
项目结构
ks@ubuntu:/work/project$ ls ndemotest -1ndemotest:setup.pytestsNAME_test.py__pycache__
项目根目录下的setup.py
内容如下:
from distutils.command.install_data import install_datapackages = ['tests', ]scripts = ['tests/NAME_test.py']cmdclasses = {'install_data': install_data}# data_files = [('etc', ['etc/myproject.cfg'])]setup_args = { 'name': 'myproject', 'version': '0.1', 'packages': packages, 'cmdclass': cmdclasses, 'data_files': "", 'scripts': scripts, # 'include_package_data': True, # 'test_suite': 'nose.collector'}try: from setuptools import setupexcept ImportError: from distutils.core import setupsetup(**setup_args)
测试用例
tests/NAME_test.py
文件内容如下:
from nose import toolsclass TestNameTest: def __init__(self): pass def setup(self): print("start!") def teardown(self): print("End....") def testfunc1(self): a = 1 b = 1 tools.ok_(a == b, "通过") print("case1通过") def testfunc2(self): a = 2 b = 1 tools.ok_(a == b, "失败") print("case2失败")
测试结果
运行测试时输出如下信息:
ks@ubuntu:/work/project/ndemotest$ python3 setup.py testrunning testWARNING: Testing via this command is deprecated and will be removed in a future version.Users looking for a generic test entry point independent of test runner are encouraged to use tox.running egg_info...creating myproject.egg-inf...writing top-level names to myproject.egg-info/top_level.txtwriting manifest file 'myproject.egg-info/SOURCES.txt'package init file 'tests/__init__.py' not found (or not a regular file)reading manifest file 'myproject.egg-info/SOURCES.txt'writing manifest file 'myproject.egg-info/SOURCES.txt'running build_extNAME_test.TestNameTest.testfunc1 ... okNAME_test.TestNameTest.testfunc2 ... FAIL
测试结果说明:
testfunc1
通过。testfunc2
失败,原因是:
AssertionError: 失败
详细信息如下:
-------------------- begin captured stdout ---------------------start!End....-------------------- end captured stdout ---------------------
测试失败原因:
- 测试方法
testfunc2
中,a
和b
不相等,导致AssertionError
。 - 测试用例失败,需修复相关逻辑。
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月25日 16时15分57秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Boostrap技能点整理之【网格系统】
2019-03-11
javaWeb服务详解(含源代码,测试通过,注释) ——Emp的Dao层
2019-03-11
Git简单理解与使用
2019-03-11
echarts 基本图表开发小结
2019-03-11
adb通过USB或wifi连接手机
2019-03-11
JDK9-15新特性
2019-03-11
Vector 实现类
2019-03-11
HashMap类、HashSet
2019-03-11
HashTable类
2019-03-11
TreeSet、TreeMap
2019-03-11
JVM内存模型
2019-03-11
可变长度参数
2019-03-11
堆空间常用参数总结
2019-03-11
3、条件查询
2019-03-11
cordova打包apk更改图标
2019-03-11
GitHub上传时,项目在已有文档时直接push出现错误解决方案
2019-03-11
页面置换算法
2019-03-11
文件系统的层次结构
2019-03-11
减少磁盘延迟时间的方法
2019-03-11