gitlabci.yml:'script:pytest'命令无法识别

2024-05-18 09:08:58 发布

您现在位置:Python中文网/ 问答频道 /正文

在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: 'script: -pytest cannot find any tests to check'

你能建议如何在windows上通过此测试吗


Tags: sampletest程序ci示例pytestwindowsyml
2条回答

以下命令工作正常,没有任何问题:

py -m pytest -s Target\tests

如果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,则需要在.gitlab.yml中使用python Docker映像

Patrick Kennedy中的“Setting Up GitLab CI for a Python Application

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

相关问题 更多 >