我想知道是否有针对pylint和/或pyflakes的鼻部插件?
目前,我正在使用coverage和tissue (PEP8)插件进行鼻部测试。
提前使用Tnx
发布于 2012-09-12 18:00:10
我曾经写过一个使用Pyflake的测试生成器。它不是一个鼻子插件,但它足够接近我的需求:
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来测试其他目录。
https://stackoverflow.com/questions/12227443
复制相似问题