右键运行pytest run时报错,原因是pytest版本过高导致的。有时候会遇到在自己本机没问题,拉取服务器代码下来后就出问题了,所以把pytest版本改低就可以,亲测有效,希望对你有帮助
完整报错信息:
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\_pytest\main.py", line 191, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\_pytest\main.py", line 234, in _main
INTERNALERROR> config.hook.pytest_collection(session=session)
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\pluggy\hooks.py", line 289, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\pluggy\manager.py", line 81, in <lambda>
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\_pytest\main.py", line 244, in pytest_collection
INTERNALERROR> return session.perform_collect()
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\_pytest\main.py", line 438, in perform_collect
INTERNALERROR> self.config.pluginmanager.check_pending()
INTERNALERROR> File "E:\Program Files\Develop\Python37\lib\site-packages\pluggy\manager.py", line 270, in check_pending
INTERNALERROR> % (name, hookimpl.plugin),
INTERNALERROR> pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace' in plugin <module 'allure.pytest_plugin' from 'E:\\Program Files\\Develop\\Python37\\lib\\site-packages\\allure\\pytest_plugin.py'>
检查自己的pytest版本为: pytest 5.1.2
卸载已有的pytest
pip uninstall pytest
指定安装pytest4.0.2版本:
pip install pytest==4.0.2
安装成功后,再次运行成功
============================= test session starts =============================
platform win32 -- Python 3.7.4, pytest-4.0.2, py-1.8.0, pluggy-0.12.0 -- E:\Program Files\Develop\Python37\python.exe
cachedir: .pytest_cache
rootdir: D:\workresource\PythonProject\Python_API\tests, inifile:
plugins: allure-adaptor-1.7.10
collecting ... collected 1 item
test_API.py::TestRun::test_YLMY_login PASSED [100%]
========================== 1 passed in 0.11 seconds ===========================