gitlab-ci.yml: 'script: -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 OS 上,但测试仍然失败。 我已经尝试了下面线程中建议的解决方案,但它不起作用:

能否建议如何让这个测试在 windows 上通过?

如果 python 被识别,您可以将 pytest 替换为 with this similar project,并替换为:

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

initial switch to pytest失败)

如果您想使用 pytest,您需要在 .gitlab.yml.

中使用 python Docker 图像

参见“Setting Up GitLab CI for a Python Application" from Patrick Kennedy

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