在PyDev中配置py.test(Python 3,Mac)

时间:2016-10-23 05:04:23

标签: python python-3.x pydev pytest

我有一台Mac,并已将py.test安装到Python 3库(而不是Apple的标准Python 2.7库)。这是因为我使用的是Python 3。

但是,当我在PyDev中运行py.test时,会发生以下错误。关于如何解决这个问题的任何解释?我已经考虑了这个问题很长一段时间了。

collected 1 items
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/main.py", line 96, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/main.py", line 130, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/main.py", line 139, in pytest_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/main.py", line 592, in perform_collect
INTERNALERROR>     config=self.config, items=items)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/mark.py", line 84, in pytest_collection_modifyitems
INTERNALERROR>     if not matchmark(colitem, matchexpr):
INTERNALERROR>   File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/_pytest/mark.py", line 124, in matchmark
INTERNALERROR>     return eval(markexpr, {}, MarkMapping(colitem.keywords))
INTERNALERROR>   File "<string>", line 1
INTERNALERROR>     axfail=2
INTERNALERROR>           ^
INTERNALERROR> SyntaxError: invalid syntax

这是一张图片:

Image

注意:我已经在LiClipse中安装了PyDev。我根据文档配置了py.test测试运行器:

--maxfail=2 --tb=native

然后我根据py.test的文档运行了一个简单的py.test测试文件:

def func(x):
    return x + 1

def test_answer():
    assert func(3) == 5

1 个答案:

答案 0 :(得分:0)

pytest配置似乎是正确的。

所以,有些事要检查:

  1. 可以使用py.test filename在命令行(LiClipse外)运行吗?

  2. 您究竟如何运行测试? (在该文件上按Ctrl + F9还是运行文件夹?)

  3. 错误似乎是在评估pytest中的标记时(即:pytest.mark.xxx),是否有可能在项目的其他部分有一些无效标记?