Azure DevOps - Pytest 单元测试开始失败
Azure DevOps - Pytest unit tests started failing
我有一个 python 应用程序,它有 pytest 单元测试 运行 作为 Azure DevOps 构建的一部分。今天早上测试开始失败,没有对代码进行任何更改。
这是一个最小的可重现示例。我有一个名为 test_a.py
的文件,其中包含以下内容:
def test_assert_true():
assert True
这是我的构建管道:
trigger:
- '*'
pool:
vmImage: windows-latest
name: 'Azure Pipelines'
stages:
- stage: Build
jobs:
- job: RunPythonUnitTests
displayName: Test - Python Unit Tests
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
architecture: 'x64'
- script: |
pip install pytest pytest-azurepipelines pyspark
pytest
displayName: 'Run tests'
Run Tests
步骤失败。日志显示以下错误:
============================= test session starts =============================
platform win32 -- Python 3.7.9, pytest-7.1.0, pluggy-1.0.0
rootdir: D:\a\s
plugins: azurepipelines-0.8.0
collected 1 item
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\_pytest\main.py", line 268, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\_pytest\main.py", line 321, in _main
INTERNALERROR> config.hook.pytest_collection(session=session)
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\_pytest\main.py", line 332, in pytest_collection
INTERNALERROR> session.perform_collect()
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\_pytest\main.py", line 659, in perform_collect
INTERNALERROR> self.config.pluginmanager.check_pending()
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_manager.py", line 265, in check_pending
INTERNALERROR> % (name, hookimpl.plugin),
INTERNALERROR> pluggy._manager.PluginValidationError: unknown hook 'pytest_warning_captured' in plugin <module 'pytest_azurepipelines' from 'c:\hostedtoolcache\windows\python\3.7.9\x64\lib\site-packages\pytest_azurepipelines.py'>
Result Attachments will be stored in LogStore
有人知道如何解决这个问题吗?
看起来这是由于 pytest
的最新版本中的重大更改造成的。
https://pypi.org/project/pytest/#history
通过在管道中指定以前的版本修复了它:
- script: |
pip install pytest==7.0.1 pytest-azurepipelines pyspark
pytest
我有一个 python 应用程序,它有 pytest 单元测试 运行 作为 Azure DevOps 构建的一部分。今天早上测试开始失败,没有对代码进行任何更改。
这是一个最小的可重现示例。我有一个名为 test_a.py
的文件,其中包含以下内容:
def test_assert_true():
assert True
这是我的构建管道:
trigger:
- '*'
pool:
vmImage: windows-latest
name: 'Azure Pipelines'
stages:
- stage: Build
jobs:
- job: RunPythonUnitTests
displayName: Test - Python Unit Tests
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
architecture: 'x64'
- script: |
pip install pytest pytest-azurepipelines pyspark
pytest
displayName: 'Run tests'
Run Tests
步骤失败。日志显示以下错误:
============================= test session starts =============================
platform win32 -- Python 3.7.9, pytest-7.1.0, pluggy-1.0.0
rootdir: D:\a\s
plugins: azurepipelines-0.8.0
collected 1 item
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\_pytest\main.py", line 268, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\_pytest\main.py", line 321, in _main
INTERNALERROR> config.hook.pytest_collection(session=session)
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\_pytest\main.py", line 332, in pytest_collection
INTERNALERROR> session.perform_collect()
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\_pytest\main.py", line 659, in perform_collect
INTERNALERROR> self.config.pluginmanager.check_pending()
INTERNALERROR> File "c:\hostedtoolcache\windows\python.7.9\x64\lib\site-packages\pluggy\_manager.py", line 265, in check_pending
INTERNALERROR> % (name, hookimpl.plugin),
INTERNALERROR> pluggy._manager.PluginValidationError: unknown hook 'pytest_warning_captured' in plugin <module 'pytest_azurepipelines' from 'c:\hostedtoolcache\windows\python\3.7.9\x64\lib\site-packages\pytest_azurepipelines.py'>
Result Attachments will be stored in LogStore
有人知道如何解决这个问题吗?
看起来这是由于 pytest
的最新版本中的重大更改造成的。
https://pypi.org/project/pytest/#history
通过在管道中指定以前的版本修复了它:
- script: |
pip install pytest==7.0.1 pytest-azurepipelines pyspark
pytest