Azure DevOps - Pytest单元测试开始失败

3

我有一个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

有人知道如何解决这个问题吗?

1个回答

3
似乎这是由于最新版本的pytest引起的重大变化造成的。
通过在管道中指定先前的版本来解决了这个问题: https://pypi.org/project/pytest/#history
- script: |
    pip install pytest==7.0.1 pytest-azurepipelines pyspark 
    pytest  

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接