简体   繁体   English

gitlab-ci.yml:“脚本:-pytest”命令无法识别

[英]gitlab-ci.yml: 'script: -pytest' command is not recognized

I'm having trouble implementing an sample program that runs pytest within .gitlab-ci.yml on Windows:我无法在 Windows 上实现在 .gitlab-ci.yml 中运行 pytest 的示例程序:

Using Shell executor...使用 Shell 执行器...

Please find below .gitlab-ci.yml:请在下面找到 .gitlab-ci.yml:

# .gitlab-ci.yml

test_sample:
  stage: test
  tags: 
    - test_sam
  script:
    - echo "Testing"
    - pytest -s Target\tests 
  when: manual

CI/CD terminal output: CI/CD端子输出:

pytest is not recognized as the name of a cmdlet, function, script file, or operable program.

Python and pytest is already installed on the Windows OS on which the test is running but still the test fails. Python 和 pytest 已安装在运行测试的 Windows 操作系统上,但测试仍然失败。 I have tried the solution suggested in below thread but it doesn't work: gitlab-ci.yml: 'script: -pytest cannot find any tests to check'我已经尝试了以下线程中建议的解决方案,但它不起作用: gitlab-ci.yml:'脚本:-pytest 找不到任何要检查的测试'

Could you please suggest how to make this test pass on windows?您能否建议如何在 Windows 上通过此测试?

If python is recognized, you could replace pytest , as with this similar project , with:如果python被识别,你可以替换pytest ,就像这个类似的项目一样:

unittests:
  script: python -m unittest discover tests -v
core doctests:
  script: python -m doctest -v AmpScan/core.py
registration doctests:
  script: python -m doctest -v AmpScan/registration.py
align doctests:
  script: python -m doctest -v AmpScan/align.py

(The initial switch to pytest failed) 初始切换到pytest失败)

If you want to use pytest, you would need to use a python Docker image in your .gitlab.yml .如果要使用 pytest,则需要在.gitlab.yml中使用 python Docker 映像。

See " Setting Up GitLab CI for a Python Application " from Patrick Kennedy .请参阅Patrick Kennedy的“ 为 Python 应用程序设置 GitLab CI ”。

image: "python:3.7"

before_script:
  - python --version
  - pip install -r requirements.txt

stages:
  - Static Analysis
  - Test
...
unit_test:
  stage: Test
  script:
  - pwd
  - ls -l
  - export PYTHONPATH="$PYTHONPATH:."
  - python -c "import sys;print(sys.path)"
  - pytest

下面的命令没有任何问题:

py -m pytest -s Target\tests

暂无
暂无

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

相关问题 每个python脚本是否可以在.gitlab-ci.yml文件中填充变量? - Is it possible to fill a variable in the .gitlab-ci.yml file per python script? 在Gitlab中配置.gitlab-ci.yml文件以测试python代码 - Configuring .gitlab-ci.yml file in Gitlab to test python Codes gitlab-ci.yml python -c'多行cmd'失败 - gitlab-ci.yml python -c 'multiple line cmd' failed 如何在 gitlab-ci.yml 中将 postgis 扩展添加到 postgresql 数据库 - How to add postgis extension to postgresql database in gitlab-ci.yml 我的 first.gitlab-ci.yml 文件:如何在 CI/CD 中运行现有文件 - My first .gitlab-ci.yml file: How to run existing files in CI/CD 如何在 Gitlab 中为简单的 hello world 程序配置 gitlab-ci.yml - How do I configure gitlab-ci.yml for a simple hello world program in Gitlab Gitlab Flask Page: Problems with installing python GDAL package for Frozen Flask Application with.gitlab-ci.yml file - Gitlab Flask Page: Problems with installing python GDAL package for Frozen Flask Application with .gitlab-ci.yml file 如何从 .gitlab-ci.yml 文件中提取单个管道名称? - How to extract individual Pipeline names from .gitlab-ci.yml file? 在.gitlab-ci.yml中使用apt-get install python包 - use apt-get install python packages in .gitlab-ci.yml .gitlab-ci.yml 缓存/工件配置,用于根据条件为后续管道/阶段保存大型二进制文件 - .gitlab-ci.yml cache/artifact configuration for saving large binaries for subsequent pipeline/stages based on condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM