pytest pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace'報錯處理辦法

1、背景說明

上週測試的同事說pytest+allure環境在別人電腦上跑沒問題,在她的環境跑卻報錯讓幫看一下。其實pytest只是據說過allure直接沒聽過,但不能直接表示不會,祭出百度大法。html

看環境pytest直接以python庫的形式安裝就能夠了:pip install pytest pytest-allure-adaptor pytest-rerunfailures pytest-htmlpython

allure安裝也簡單下載解壓而後將bin目錄添加到環境變量便可。下載地址:https://github.com/allure-framework/allure2/releases/tag/2.10.0git

 

2、問題處理

2.1 報錯描述

主要運行報錯以下:github

pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace' in plugin <module 'allure.pytest_plugin' from 'd:\\language\\miniconda3\\e
nvs\\pytest\\lib\\site-packages\\allure\\pytest_plugin.py'>

完整報錯以下:session

F:\PycharmProjects\pytest>pytest
==================================================================== test session starts =====================================================================
platform win32 -- Python 3.6.6, pytest-4.3.0, py-1.7.0, pluggy-0.8.1
rootdir: F:\PycharmProjects\pytest, inifile: pytest.ini
plugins: rerunfailures-6.0, metadata-1.8.0, html-1.20.0, allure-adaptor-1.7.10
collecting 1 item                                                                                                                                             I
NTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\_pytest\main.py", line 210, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\_pytest\main.py", line 249, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\pluggy\hooks.py", line 284, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\pluggy\manager.py", line 68, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\pluggy\manager.py", line 62, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\_pytest\main.py", line 259, in pytest_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\_pytest\main.py", line 487, in perform_collect
INTERNALERROR>     self.config.pluginmanager.check_pending()
INTERNALERROR>   File "d:\language\miniconda3\envs\pytest\lib\site-packages\pluggy\manager.py", line 251, in check_pending
INTERNALERROR>     % (name, hookimpl.plugin),
INTERNALERROR> pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace' in plugin <module 'allure.pytest_plugin' from 'd:\\language\\miniconda3\\e
nvs\\pytest\\lib\\site-packages\\allure\\pytest_plugin.py'>
View Code

 

2.2 報錯處理

反覆從新建立配置了環境忽然某次成功運行了,回頭排除項目使用中文路徑、python環境使用中文路徑、使用conda發行版後,想起google到的某個頁面說過是版本問題並且本身也按其建議裝了舊版本:ide

最後肯定確實如其所說,pytest新版本(我當前是4.3.0)運行報錯,換成4.0.2版本就不會報錯:測試

# 卸載已安裝的pytest
pip uninstall pytest
# 安裝4.0.2版本pytest pip install pytest==4.0.2

成功運行以下圖:google

 

參考:spa

https://github.com/nucypher/nucypher/issues/649code

相關文章
相關標籤/搜索