Mat*_*usz 5 python pep8 pytest
我一直在关注 Head First Python 第二版,在第 4 章中演示了 pep8 合规性测试。尽管代码与书中相同,但我的输出是不同的。
\n\n测试代码非常简单:
\n\ndef search4vowels(phrase: str) -> set:\n """Return vowels found in supplied phrase."""\n vowels = set(\'aeiou\')\n return vowels.intersection(set(phrase))\n\n\ndef search4letters(phrase: str, letters: str=\'aeiou\') -> set:\n """Return a set of \'letters\' found in \'phrase\'."""\n return set(letters).intersection(set(phrase))\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试按照书中所示进行测试,并得到以下输出:
\n\n\xce\xbb py.test.exe --pep8 vsearch.py\nc:\\users\\gx\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\pep8.py:110: FutureWarning: Possible nested set at position 1\n EXTRANEOUS_WHITESPACE_REGEX = re.compile(r\'[[({] | []}),;:]\')\n============================= test session starts =============================\nplatform win32 -- Python 3.7.4, pytest-5.1.1, py-1.8.0, pluggy-0.12.0\nrootdir: C:\\Users\\gx\\Desktop\\H.F. Python\\mymodules\nplugins: pep8-1.0.6\ncollected 1 item\n\nvsearch.py . [100%]\n\n============================== warnings summary ===============================\nc:\\users\\gx\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\_pytest\\mark\\structures.py:324\n c:\\users\\gx\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\_pytest\\mark\\structures.py:324:\nPytestUnknownMarkWarning: Unknown pytest.mark.pep8 - is this a typo?\nYou can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html\n PytestUnknownMarkWarning,\n\n-- Docs: https://docs.pytest.org/en/latest/warnings.html\n======================== 1 passed, 1 warnings in 0.04s ========================\nRun Code Online (Sandbox Code Playgroud)\n\n(我稍微修改了空格以使其更具可读性)
\n\n在书中没有发生这样的事情。\n在执行此操作之前,我已经新安装了 pytest 和 pytest-pep8,如书中所示。
\n\n这是什么原因造成的?
\n这似乎是一个已知问题:#23。解决方法是将pep8标记注册到pytest.ini:
[pytest]
markers =
pep8: workaround for https://bitbucket.org/pytest-dev/pytest-pep8/issues/23/
Run Code Online (Sandbox Code Playgroud)
或以编程方式将其注册在conftest.py:
def pytest_configure(config):
config.addinivalue_line(
'markers', 'pep8: workaround for https://bitbucket.org/pytest-dev/pytest-pep8/issues/23/'
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1419 次 |
| 最近记录: |