简体   繁体   English

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

[英]Configuring py.test in PyDev (Python 3, Mac)

I have a Mac and have installed py.test to the Python 3 library (instead of Apple's standard Python 2.7 library). 我有一台Mac,并且已将py.test安装到Python 3库(而不是Apple的标准Python 2.7库)。 This is because I'm using Python 3. 这是因为我正在使用Python 3。

When I run py.test in PyDev, however, the following error occurs. 但是,当我在PyDev中运行py.test时,会发生以下错误。 Any explanation on how to solve this? 关于如何解决这个问题的任何解释? I've pondered this question for quite some time. 我已经思考了很长时间了。

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

Here's a picture: 这是一张图片:

Image 图片

Notes: I've installed PyDev bundled in LiClipse. 注意:我已经安装了LiClipse中捆绑的PyDev。 I've configured the py.test test runner according to the documentation: 我已经根据文档配置了py.test测试运行程序:

--maxfail=2 --tb=native

I then ran a simple py.test test file according to py.test's documentation: 然后,我根据py.test的文档运行了一个简单的py.test测试文件:

def func(x):
    return x + 1

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

The pytest configuration seems correct. pytest配置似乎正确。

So, some things to check: 因此,要检查一些事情:

  1. Can you run it in the command line (out of LiClipse) with py.test filename ? 您可以使用py.test filename在命令行中(不在LiClipse中)运行它吗?

  2. How exactly are you running the tests? 您如何精确地运行测试? (Ctrl+F9 on that file or running a folder?) (该文件或运行文件夹是Ctrl + F9还是?)

The error seems to be when evaluating a mark in pytest (ie: pytest.mark.xxx), is it possible that you have some invalid mark in some other part of your project? 错误似乎是在评估pytest中的标记(即pytest.mark.xxx)时出现的,您的项目其他部分是否可能存在无效标记?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM