一个支持用嵌套上下文编写描述/it风格单元测试的nose插件

describe_it的Python项目详细描述


buildstatus

描述它是一个nose插件,允许您编写更多的单元测试 类似于一个组件应该如何工作而不仅仅是测试的可执行示例。

另一个好处是能够描述组件在特定情况下的行为 上下文,其中一个上下文可以通过使用 筑巢。

安装

$ pip install describe-it

写入

以“spec”结尾的任何模块都被视为包含规范/测试 为了描述它。

$ vim myfirst_spec.py

…内容:

fromgameimportGamefromdescribe_itimportdescribe,it,before_each,Fixture@describe# This declares a test context.defa_game():f=Fixture()# Fixture is a hack to get around# Python's implementation of closures.# You can use other methods, such as# nonlocal if you like.@before_each# Will be called before each 'it'defsetup():f.game=Game()@after_each# Will be called after each 'it'defteardown():perform_post_test_cleanup_if_needed()# This should rarely be needed!@it# This marks a test method.defis_player_ones_turn():assertf.game.current_player==1# describe_it doesn't come with an# assertion lib. Pick any one you like.@describe# This is a nested context thatdefin_second_round():# augments the context above.@before_each# Before each 'it' method, anydefsetup():# before_each in outer contexts willf.game.play_round()# be called first. Then this method# will be called.@itdefis_player_twos_turn():assertf.game.current_player==2@xit# You can skip individual test methodsdefskips_tests():# by using '@xit' or '@it_skip'assertTrue@with_data([1,2,3],# You can parameterize tests with[3,4,7])# different combinations of inputsdefadds_numbers(term_1,term_2,expected):assertterm_1+term_2==expected@xdescribe# You can skip whole contexts bydefthis_context_is_marked_as_skipped():# using '@xdescribe' or '@describe_skip'@itdefthis_test_will_be_skipped():assertTrue

运行

$ nosetests --with-describe-it

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java我能在这个程序中更好地使用内存吗?   为什么我的Java while循环迭代了一半   java IntelliJ IDEA不在构建时复制资源   socket仅在Java TCP服务器输出上检查客户端断开连接   java游戏物理摩擦   java片段onClick调用方法   symja数学分析器中无法识别java Abs[x]   java在使用泛型时创建二进制搜索树类的实例?   java在外键约束表上的添加和删除   语法java表达式的含义,如果有条件   java创建内联对象并作为参数传递   是否有相当于Redis排序集(zset)的Java数据结构   java找不到适合的方法(无参数)   音频文件操作给定字节帧的音量Java   Eclipse4不以JavaWebStart启动   java如何使用org在JSON对象中获取嵌套的键元素。json?   java与Jackson的反序列化:“org.codehaus.Jackson.map.JsonMappingException:无法反序列化[projectname]的实例。”   字符串的Java正则表达式   spring集成上的java检测缺火指令