Azure-pipelines:没有名为“xmlrunner”的模块

发布于 2025-01-10 19:13:59 字数 2559 浏览 0 评论 0原文

Stackoverflow 中的 Azure Pipelines 问题似乎有很多“没有模块名称...”...现在,由于它们都没有帮助我,轮到我了:(

这是我正在尝试运行的管道:一个简单的CI 测试我的 Django 应用程序,基于 Microsoft 自己的模板:

trigger:
- master

pool:
  vmImage: ubuntu-latest
strategy:
  matrix:
    Python310:
      PYTHON_VERSION: '3.10'
  maxParallel: 2

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '$(PYTHON_VERSION)'
    architecture: 'x64'

- task: DownloadSecureFile@1
  name: dotEnv
  inputs:
    secureFile: 'uploaded.env'

- task: PythonScript@0
  displayName: 'Export project path'
  inputs:
    scriptSource: 'inline'
    script: |
      """Search all subdirectories for `manage.py`."""
      from glob import iglob
      from os import path
      # Python >= 3.5
      manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None)
      if not manage_py:
          raise SystemExit('Could not find a Django project')
      project_location = path.dirname(path.abspath(manage_py))
      print('Found Django project in', project_location)
      print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location))

- task: CopyFiles@2
  displayName: 'Add .env file'
  inputs:
    SourceFolder: '$(Agent.TempDirectory)'
    Contents: 'uploaded.env'
    TargetFolder: '$(projectRoot)'
  
- script: mv uploaded.env .env
  displayName: 'Rename .env file'

- script: |
    python -m pip install --upgrade pip setuptools wheel
    python -m pip install poetry
    python -m pip install unittest-xml-reporting xmlrunner
    poetry install
  displayName: 'Install dependencies'

- script: |
    pushd '$(projectRoot)'
    poetry run python manage.py test --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner --no-input
    poetry run coverage xml
  displayName: 'Run tests'

- task: PublishTestResults@2
  inputs:
    testResultsFiles: "**/TEST-*.xml"
    testRunTitle: 'Python $(PYTHON_VERSION)'
  condition: succeededOrFailed()

- task: PublishCodeCoverageResults@1
  inputs:
     codeCoverageTool: Cobertura
     summaryFileLocation: 'coverage.xml'
     reportDirectory: 'htmlcov'
  displayName: 'Publish Coverage Results'

这在测试阶段失败,并出现错误: ModuleNotFoundError: No module named 'xmlrunner'

对我来说最奇怪的是我看到xmlrunner 在前面的步骤中安装:

在此处输入图像描述

以前有人遇到过这种情况吗?

编辑:我最近遇到了同样的问题当我的时候出现了不同的问题。迁移到 Poetry 和 Python 3.10,因此两者之一可能是罪魁祸首。

There seem to be many "No module names..." on Azure Pipelines issues in Stackoverflow... and now, as none of them helped me, it's my turn :(

This is the pipeline I'm trying to run: a simple CI to test my Django app, based on Microsoft's own template:

trigger:
- master

pool:
  vmImage: ubuntu-latest
strategy:
  matrix:
    Python310:
      PYTHON_VERSION: '3.10'
  maxParallel: 2

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '$(PYTHON_VERSION)'
    architecture: 'x64'

- task: DownloadSecureFile@1
  name: dotEnv
  inputs:
    secureFile: 'uploaded.env'

- task: PythonScript@0
  displayName: 'Export project path'
  inputs:
    scriptSource: 'inline'
    script: |
      """Search all subdirectories for `manage.py`."""
      from glob import iglob
      from os import path
      # Python >= 3.5
      manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None)
      if not manage_py:
          raise SystemExit('Could not find a Django project')
      project_location = path.dirname(path.abspath(manage_py))
      print('Found Django project in', project_location)
      print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location))

- task: CopyFiles@2
  displayName: 'Add .env file'
  inputs:
    SourceFolder: '$(Agent.TempDirectory)'
    Contents: 'uploaded.env'
    TargetFolder: '$(projectRoot)'
  
- script: mv uploaded.env .env
  displayName: 'Rename .env file'

- script: |
    python -m pip install --upgrade pip setuptools wheel
    python -m pip install poetry
    python -m pip install unittest-xml-reporting xmlrunner
    poetry install
  displayName: 'Install dependencies'

- script: |
    pushd '$(projectRoot)'
    poetry run python manage.py test --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner --no-input
    poetry run coverage xml
  displayName: 'Run tests'

- task: PublishTestResults@2
  inputs:
    testResultsFiles: "**/TEST-*.xml"
    testRunTitle: 'Python $(PYTHON_VERSION)'
  condition: succeededOrFailed()

- task: PublishCodeCoverageResults@1
  inputs:
     codeCoverageTool: Cobertura
     summaryFileLocation: 'coverage.xml'
     reportDirectory: 'htmlcov'
  displayName: 'Publish Coverage Results'

This fails on the testing stage, with the error: ModuleNotFoundError: No module named 'xmlrunner'

The strangest thing to me is that I see xmlrunner being installed in the previous steps:

enter image description here

Has anyone been through this before?

Edit: I've recently come across the same problem with a different repo. The issue appeared when I migrated to Poetry and Python 3.10, so one of the 2 might be the culprit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2025-01-17 19:13:59

您正在 pip 安装 xmlrunnerunittest-xml-reporting,但您可能想要的只是 unittest-xml-reportingxmlrunner 是另一个 PyPi 库。

You're pip-installing both xmlrunner and unittest-xml-reporting, but all you probably want is unittest-xml-reporting. xmlrunner is another PyPi library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文