坑:pytest 運行報錯unknown hook 'pytest_namespace' in plugin


右鍵運行pytest run時報錯,原因是pytest版本過高導致的。有時候會遇到在自己本機沒問題,拉取服務器代碼下來后就出問題了,所以把pytest版本改低就可以,親測有效,希望對你有幫助

完整報錯信息如下:

plugins: allure-adaptor-1.7.10, forked-1.0.2, html-1.20.0, metadata-1.8.0, xdist-1.29.0
collected 17 items / 1 errors / 16 selected
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\_pytest\main.py", line 213, in wrap_
session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\_pytest\main.py", line 256, in _main

INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "e:\python3\python3.7.332\lib\site-packages\pluggy\hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "e:\python3\python3.7.332\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "e:\python3\python3.7.332\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:\python3\python3.7.332\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "e:\python3\python3.7.332\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "e:\python3\python3.7.332\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\_pytest\main.py", line 266, in pytes
t_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\_pytest\main.py", line 460, in perfo
rm_collect
INTERNALERROR>     self.config.pluginmanager.check_pending()
INTERNALERROR>   File "e:\python3\python3.7.332\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' fr
om 'e:\\python3\\python3.7.332\\lib\\site-packages\\allure\\pytest_plugin.py'>

  

具體解決方案如下:

1、檢查自己的pytest版本為5.0.0

 

2、卸載已有的pytest

pip uninstall pytest

 

 3、指定安裝pytest4.0.2版本:

pip install pytest==4.0.2

進入設置查看安裝成功

 

4、再次右鍵使用pytest運行代碼,運行成功,結果如下

 

 

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM