首页 > 解决方案 > pep8 合规性测试失败

问题描述

我遵循了 Head First Python 2nd Edition,第 4 章演示了 pep8 合规性测试。

运行 py.test --pep8 searchV.py 时 出现 错误

appdata\local\programs\python\python38\lib\site-packages\pep8.py:110:FutureWarning:可能嵌套在位置 1 EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),; :]') ===============测试会话开始 ============================ ============= 平台 win32 -- Python 3.8.6, pytest-6.2.1, py-1.10.0, pluggy-0.13.1 rootdir: D:\work\py-modules 插件: pep8-1.0.6 收集到 0 个项目 / 1 个错误

=============== 错误 =================================== ===================== _______________ERROR 收集测试会话 ____ 直接构建 Pep8Item 已被弃用,请使用 Pep8Item.from_parent。有关更多详细信息,请参阅https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent。==========简短的测试摘要信息 ================ 错误!!!!!!!!!!!!!!!!!!!!!中断:收集过程中出现 1 个错误!!!!!!!!!!!!!!!!!!!!!!

这是 serachV.py 中的代码

def search_letter(phrase: str , letter:str='aeiou')->set:
    """ Serach for letter in phrase"""
    return set(letter).intersection(set(phrase))

不知道为什么没有收集物品?

标签: python-3.xpytestpep8

解决方案


尝试pep8 searchV.py而不是代替py.test --pep8 searchV.py 并且它起作用了。

但是 pep8 已重命名为 pycodestyle (GitHub issue #466) 。pep8 工具的使用将在未来的版本中删除。

所以,我使用了 pycodestyle 并且成功了!

pycodestyle searchV.py

推荐阅读