Azure-pipelines:没有名为“xmlrunner”的模块
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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在 pip 安装
xmlrunner
和unittest-xml-reporting
,但您可能想要的只是unittest-xml-reporting
。xmlrunner
是另一个 PyPi 库。You're pip-installing both
xmlrunner
andunittest-xml-reporting
, but all you probably want isunittest-xml-reporting
.xmlrunner
is another PyPi library.