Azure Devops pipeline pytest collection failure ModuleNotFoundError: No module named

Azure Devops pipeline pytest collection failure ModuleNotFoundError: No module named

我在 运行连接 Azure 管道时收到以下错误。

这是我的管道 yaml 文件的 pytest 部分。

 steps:
  #test
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '$(python.version)'
    displayName: 'Use Python $(python.version)'

  #test
  - script: |
      python -m pip install --upgrade pip
      python -m pip install wheel
      pip install -r requirements.txt
    condition: ne(variables.CACHE_RESTORED, 'true')
    displayName: 'Install dependencies'
  #test
  - script: |
      python -m spacy download de_core_news_sm
      python -m spacy download de_core_news_md
  #test
  - script: |
      pip install pytest pytest-azurepipelines
      pytest
    displayName: 'pytest'

文件 tat_core/criteria/checks/zw2n_test.py 在我的本地存储库副本中不存在。我删了

如何告诉管道文件不存在并且测试不必是运行?我假设路径 /opt/hostedtoolscache 指示存在某种缓存。我可以清空这个缓存吗?

您可以尝试从您的项目中删除“__init__.py”文件,看看它是否可以工作,如中所述。

此外,请在您的本地机器上对同一项目尝试pytest,看看是否会出现同样的问题。

我将模块 'zahlwort2num' 添加到 requirements.txt。管道现在运行。 requirements.txt 中未使用的依赖项是一个缺点。