【问题标题】:Is there a plugin for pylint and pyflakes for nose tests?是否有用于鼻子测试的 pylint 和 pyflakes 插件?
【发布时间】:2012-09-01 11:47:15
【问题描述】:

我想知道是否有用于 pylint 和/或 pyflakes 的鼻子插件?

目前我正在使用coveragetissue (PEP8) 插件进行鼻子测试。

提前发送

【问题讨论】:

    标签: python testing pylint nosetests pyflakes


    【解决方案1】:

    我曾经写过一个使用 Pyflakes 的测试生成器。它不是一个鼻子插件,但它已经足够满足我的需要了:

    import os
    import _ast
    
    from pyflakes import checker
    
    import your_application
    
    TOP = os.path.dirname(os.path.dirname(your_application.__file__))
    
    class PyflakesError(AssertionError):
        def __str__(self):
            path = self.args[0]
            messages = self.args[1]
            messages.sort(key=lambda m: m.lineno)
            return 'checking %s\n' % path + '\n'.join(map(str, messages))
    
    def check(path):
        code = open(os.path.join(TOP, path)).read()
        tree = compile(code, path, "exec", _ast.PyCF_ONLY_AST)
        w = checker.Checker(tree, path)
        if w.messages:
            raise PyflakesError(path, w.messages)
    
    def test():
        for root, dirs, files in os.walk(TOP):
            for name in files:
                if not name.endswith('.py'):
                    continue
                yield check, os.path.relpath(os.path.join(root, name), TOP)
    
            def is_package(d):
                return os.path.exists(os.path.join(root, d, '__init__.py'))
            dirs[:] = filter(is_package, dirs)
    

    test 函数为包含your_application 的目录中的每个 Python 文件生成测试用例。您可以根据需要调整TOP以测试其他目录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多