通过pytest-xdist通过CLI运行pytest运行正常(pytest -n 3 {test})。在PyCharm中运行相同的设置时,出现上下文版本冲突,指出我需要降低pytest版本。当我将版本降低到4以下时,pycharm可以通过pytest运行程序运行pytest脚本。
这是requirements.txt:
apipkg==1.5
atomicwrites==1.3.0
attrs==19.1.0
execnet==1.5.0
more-itertools==6.0.0
pluggy==0.9.0
py==1.8.0
pytest==4.3.1
pytest-forked==1.0.2
pytest-rerunfailures==6.0
pytest-xdist==1.27.0
selenium==3.141.0
six==1.12.0
urllib3==1.24.1
和错误:
Traceback (most recent call last):
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pluggy/manager.py", line 274, in load_setuptools_entrypoints
plugin = ep.load()
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pkg_resources/init.py", line 2342, in load
self.require(*args, **kwargs)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pkg_resources/init.py", line 2365, in require
items = working_set.resolve(reqs, env, installer, extras=self.extras)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pkg_resources/init.py", line 786, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (pytest 4.3.1 (/Users//.pyenv/versions/3.6.7/lib/python3.6/site-packages), Requirement.parse('pytest<4.0.0'), {'pytest-fixture-config'})
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pycharm/_jb_pytest_runner.py", line 31, in <module>
pytest.main(args, plugins_to_load)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/_pytest/config/init.py", line 59, in main
config = _prepareconfig(args, plugins)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/_pytest/config/init.py", line 194, in _prepareconfig
pluginmanager=pluginmanager, args=args
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pluggy/hooks.py", line 289, in call
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pluggy/manager.py", line 68, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pluggy/manager.py", line 62, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pluggy/callers.py", line 203, in _multicall
gen.send(outcome)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/_pytest/helpconfig.py", line 93, in pytest_cmdline_parse
config = outcome.get_result()
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/_pytest/config/init.py", line 653, in pytest_cmdline_parse
self.parse(args)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/_pytest/config/init.py", line 870, in parse
self._preparse(args, addopts=addopts)
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/_pytest/config/init.py", line 815, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pluggy/manager.py", line 280, in load_setuptools_entrypoints
message="Plugin %r could not be loaded: %s!" % (ep.name, e),
pluggy.manager.PluginValidationError: Plugin 'webdriver' could not be loaded: (pytest 4.3.1 (/Users/{name}/.pyenv/versions/3.6.7/lib/python3.6/site-packages), Requirement.parse('pytest<4.0.0'), {'pytest-fixture-config'})!
当前在命令行上通过venv运行。
我希望能够像在CLI中一样在pycharm中运行相同的设置
答案 0 :(得分:2)
解决了该问题:PyCharm已安装pytest-fixture-config。我必须删除程序包,然后运行测试才能正常工作。 pytest-fixture-config状态Pinned pytest<4.0.0 until all deprecation warnings are fixed.