gpt4 book ai didi

python - 是否有用于 Nose 测试的 pylint 和 pyflakes 的插件?

转载 作者:太空狗 更新时间:2023-10-30 01:34:56 26 4
gpt4 key购买 nike

我想知道是否有 pylint 和/或 pyflakes 的 nose 插件?

目前我正在使用 coveragetissue (PEP8) Nose 测试插件。

提前发送

最佳答案

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

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 以测试其他目录。

关于python - 是否有用于 Nose 测试的 pylint 和 pyflakes 的插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12227443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com