首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行pytest时more-itertools中的无效语法

运行pytest时more-itertools中的无效语法
EN

Stack Overflow用户
提问于 2019-02-12 18:44:43
回答 1查看 5.1K关注 0票数 10

我有以下最小的setup.py

代码语言:javascript
复制
import setuptools

setuptools.setup(
    setup_requires=['pytest-runner'],
    tests_require=['mock', 'pytest'],
    test_suite='tests',
    python_requires='>=2.7',
)

使用运行它时

代码语言:javascript
复制
python setup.py test

我一直收到以下错误:

回溯(最近一次调用):文件"setup.py",第8行,在

代码语言:javascript
复制
<module>
    python_requires='>=2.7',   File "/Users/project/tmp/env/lib/python2.7/site-packages/setuptools/__init__.py",
line 145, in setup
    return distutils.core.setup(**attrs)   File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py",
line 151, in setup
    dist.run_commands()   File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py",
line 953, in run_commands
    self.run_command(cmd)   File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py",
line 972, in run_command
    cmd_obj.run()   File "/Users/project/tmp/.eggs/pytest_runner-4.2-py2.7.egg/ptr.py",
line 176, in run
    return self.run_tests()   File "/Users/project/tmp/.eggs/pytest_runner-4.2-py2.7.egg/ptr.py",
line 187, in run_tests
    result_code = __import__('pytest').main()   File "/Users/project/tmp/.eggs/pytest-4.2.0-py2.7.egg/pytest.py",
line 14, in <module>
    from _pytest.fixtures import fillfixtures as _fillfuncargs   File "/Users/project/tmp/.eggs/pytest-4.2.0-py2.7.egg/_pytest/fixtures.py",
line 16, in <module>
    from more_itertools import flatten   File "build/bdist.macosx-10.13-x86_64/egg/more_itertools/__init__.py", line
1, in <module  File
"/Users/project/tmp/.eggs/more_itertools-6.0.0-py2.7.egg/more_itertools/more.py",
line 329
    def _collate(*iterables, key=lambda a: a, reverse=False):
                               ^ SyntaxError: invalid syntax

当安装工具安装测试依赖项时,在第一次运行期间执行的more_itertools测试中也会出现此问题:

代码语言:javascript
复制
Downloading
https://files.pythonhosted.org/packages/dd/f4/cdfbb6f07f767e0cd8a11b16adfecc735b6eb87dbebda026ce8898e1cc22/more-itertools-6.0.0.tar.gz#sha256=590044e3942351a1bdb1de960b739ff4ce277960f2425ad4509446dbace8d9d1
Best match: more-itertools 6.0.0 Processing
more-itertools-6.0.0.tar.gz Writing
/var/folders/lq/c1ll7pqx7rb28p7m_8wz3h2d0r0mws/T/easy_install-Auek5Z/more-itertools-6.0.0/setup.cfg
Running more-itertools-6.0.0/setup.py -q bdist_egg --dist-dir
/var/folders/lq/c1ll7pqx7rb28p7m_8wz3h2d0r0mws/T/easy_install-Auek5Z/more-itertools-6.0.0/egg-dist-tmp-I3ic_t
warning: no files found matching 'fabfile.py'   File
"build/bdist.macosx-10.13-x86_64/egg/more_itertools/tests/test_more.py",
line 892
    print(item, file=f)
                    ^ SyntaxError: invalid syntax

  File "build/bdist.macosx-10.13-x86_64/egg/more_itertools/more.py",
line 329
    def _collate(*iterables, key=lambda a: a, reverse=False):
                               ^ SyntaxError: invalid syntax

zip_safe flag not set; analyzing archive contents... Copying
more_itertools-6.0.0-py2.7.egg to /Users/project/tmp/.eggs

Installed /Users/project/tmp/.eggs/more_itertools-6.0.0-py2.7.egg

使用安装more_itertools时不会出现此问题

代码语言:javascript
复制
pip install more_itertools
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-12 23:25:32

最近发布的more-itertools 6.0版似乎引入了此错误。下面应该热修复它:

代码语言:javascript
复制
import setuptools

setuptools.setup(
    setup_requires=['pytest-runner'],
    tests_require=['mock', 'more-itertools<6.0.0', 'pytest'],
    test_suite='tests',
    python_requires='>=2.7',
)

该问题已在此处进行了跟踪:https://github.com/pytest-dev/pytest/issues/4770

来源:我刚刚看到@dzieciou已经通过评论回答了。

票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54648246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档