【问题标题】:Pytest-pep8 problem while following Head First Python 2nd edition遵循 Head First Python 2nd edition 时出现 Pytest-pep8 问题
【发布时间】:2019-12-29 21:20:54
【问题描述】:

我一直在关注 Head First Python 2nd Edition,在第 4 章中,演示了 pep8 合规性测试。尽管与书中的代码相同,但我的输出却不同。

测试代码很简单:

def search4vowels(phrase: str) -> set:
    """Return vowels found in supplied phrase."""
    vowels = set('aeiou')
    return vowels.intersection(set(phrase))


def search4letters(phrase: str, letters: str='aeiou') -> set:
    """Return a set of 'letters' found in 'phrase'."""
    return set(letters).intersection(set(phrase))

我尝试按照书中所示进行测试,并得到了以下输出:

λ py.test.exe --pep8 vsearch.py
c:\users\gx\appdata\local\programs\python\python37-32\lib\site-packages\pep8.py:110: FutureWarning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
============================= test session starts =============================
platform win32 -- Python 3.7.4, pytest-5.1.1, py-1.8.0, pluggy-0.12.0
rootdir: C:\Users\gx\Desktop\H.F. Python\mymodules
plugins: pep8-1.0.6
collected 1 item

vsearch.py .                                                             [100%]

============================== warnings summary ===============================
c:\users\gx\appdata\local\programs\python\python37-32\lib\site-packages\_pytest\mark\structures.py:324
  c:\users\gx\appdata\local\programs\python\python37-32\lib\site-packages\_pytest\mark\structures.py:324:
PytestUnknownMarkWarning: Unknown pytest.mark.pep8 - is this a typo?
You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
    PytestUnknownMarkWarning,

-- Docs: https://docs.pytest.org/en/latest/warnings.html
======================== 1 passed, 1 warnings in 0.04s ========================

(我稍微修改了空格以使其更具可读性)

在书中没有发生这样的事情。 在这样做之前,我已经全新安装了 pytest 和 pytest-pep8,如书中所示。

是什么原因造成的?

【问题讨论】:

    标签: python pytest pep8


    【解决方案1】:

    这似乎是一个已知问题:#23。一种解决方法是在pytest.ini 中注册pep8 标记:

    [pytest]
    markers =
        pep8: workaround for https://bitbucket.org/pytest-dev/pytest-pep8/issues/23/
    

    或以编程方式在conftest.py 中注册它:

    def pytest_configure(config):
        config.addinivalue_line(
            'markers', 'pep8: workaround for https://bitbucket.org/pytest-dev/pytest-pep8/issues/23/'
        )
    

    【讨论】:

      猜你喜欢
      • 2021-07-07
      • 2022-06-14
      • 1970-01-01
      • 1970-01-01
      • 2013-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      相关资源
      最近更新 更多