繁体   English   中英

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

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

我无法在 Windows 上实现在 .gitlab-ci.yml 中运行 pytest 的示例程序:

使用 Shell 执行器...

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

# .gitlab-ci.yml

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

CI/CD端子输出:

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

Python 和 pytest 已安装在运行测试的 Windows 操作系统上,但测试仍然失败。 我已经尝试了以下线程中建议的解决方案,但它不起作用: gitlab-ci.yml:'脚本:-pytest 找不到任何要检查的测试'

您能否建议如何在 Windows 上通过此测试?

如果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

初始切换到pytest失败)

如果要使用 pytest,则需要在.gitlab.yml中使用 python Docker 映像。

请参阅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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM