5

I'm having trouble implementing an sample program that runs pytest within .gitlab-ci.yml on Windows:

Using Shell executor...

Please find below .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:

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. 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'

Could you please suggest how to make this test pass on windows?

user2077648
  • 951
  • 7
  • 27
  • 42

2 Answers2

3

If python is recognized, you could replace pytest, as with this similar project, with:

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)

If you want to use pytest, you would need to use a python Docker image in your .gitlab.yml.

See "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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • this does not work, I am getting error though I have installed python $ python --version python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. – user2077648 Nov 16 '20 at 17:33
  • Could you please suggest a working example because this solution is not specific to windows OS – user2077648 Nov 16 '20 at 17:34
  • $ py --version Python 3.7.5 – user2077648 Nov 16 '20 at 17:36
  • 1
    @user2077648 Double-check the %PATH% used by GitLab: it might not include the Python installation folder. – VonC Nov 16 '20 at 17:37
-1

The below command worked without any issues:

py -m pytest -s Target\tests
user2077648
  • 951
  • 7
  • 27
  • 42