支持非致命故障的Python测试框架 [英] Python test framework with support of non-fatal failures

查看:112
本文介绍了支持非致命故障的Python测试框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在评估用于自动化系统测试的测试框架";到目前为止,我正在寻找一个python框架. 在py.test或鼻子中,我看不到从Google测试框架知道的EXPECT宏之类的东西. 我想在一个测试中做出几个断言,而不会在第一次失败时中止测试. 我是否在这些框架中缺少某些内容,或者这行不通? 有人对可用于自动化系统测试的python测试framworks有建议吗?

I'm evaluating "test frameworks" for automated system tests; so far I'm looking for a python framework. In py.test or nose I can't see something like the EXPECT macros I know from google testing framework. I'd like to make several assertions in one test while not aborting the test at the first failure. Am I missing something in these frameworks or does this not work? Does anybody have suggestions for python test framworks usable for automated system tests?

推荐答案

我想要使用鼻子进行功能测试的类似方法.我最终想到了这个:

I was wanting something similar for functional testing that I'm doing using nose. I eventually came up with this:

def raw_print(str, *args):
    out_str = str % args
    sys.stdout.write(out_str)

class DeferredAsserter(object):
    def __init__(self):
        self.broken = False
    def assert_equal(self, expected, actual):
        outstr = '%s == %s...' % (expected, actual)
        raw_print(outstr)
        try:
            assert expected == actual
        except AssertionError:
            raw_print('FAILED\n\n')
            self.broken = True
        except Exception, e:
            raw_print('ERROR\n')
            traceback.print_exc()
            self.broken = True
        else:
            raw_print('PASSED\n\n')

    def invoke(self):
        assert not self.broken

换句话说,它正在打印出表明测试是否通过或失败的字符串.在测试结束时,您将调用实际上执行 real 断言的invoke方法.这绝对不是可取的,但是我还没有看到可以处理这种测试的Python测试框架.我也没有弄清楚如何编写一个鼻子插件来做这种事情. :-/

In other words, it's printing out strings indicating if a test passed or failed. At the end of the test, you call the invoke method which actually does the real assertion. It's definitely not preferable, but I haven't seen a Python testing framework that can handle this kind of testing. Nor have I gotten around to figuring out how to write a nose plugin to do this kind of thing. :-/

这篇关于支持非致命故障的Python测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆