繁体   English   中英

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\1\s
plugins: azurepipelines-0.8.0
collected 1 item
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "c:\hostedtoolcache\windows\python\3.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\3.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\3.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\3.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\3.7.9\x64\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "c:\hostedtoolcache\windows\python\3.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\3.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\3.7.9\x64\lib\site-packages\_pytest\main.py", line 332, in pytest_collection
INTERNALERROR>     session.perform_collect()
INTERNALERROR>   File "c:\hostedtoolcache\windows\python\3.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\3.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  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM