Gitlab-CI для проекта Python с SonarQube - PullRequest
0 голосов
/ 16 февраля 2020

Я хочу установить Gitlab-CI для моего python проекта с SonarQube. У меня есть одна проблема с этим. Я устанавливаю переменные SonarQube в настройках gitlab-ci.

Это мой файл gitlab-ci.yml:

variables:

    SONARQUBE_ARGUMENTS_NORMAL: -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWORD --stacktrace
    SONARQUBE_ARGUMENTS_PREVIEW: -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWORD --stacktrace -Dsonar.analysis.mode=preview -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
    STAGE_ID: ${CI_PROJECT_NAME}_${CI_BUILD_REF_NAME}_${CI_JOB_NAME}_${CI_JOB_ID}

image: "python:3.7"

before_script:
  - python --version
  - python -c 'import struct;print( 8 * struct.calcsize("P"))'
  - pip install --upgrade pip
  - pip install --upgrade setuptools
  - pip install pytest
  - pip install -r requirements.txt

stages:
  - Static Analysis
  - Test

mypy:
  stage: Static Analysis
  script:
  - python -m pip install mypy
  - pwd
  - ls -l
  - python -m mypy --ignore-missing-imports *.py

flake8:
  stage: Static Analysis
  script:
  - python -m pip install flake8
  - flake8 --max-line-length=120 /*.py

pylint:
  stage: Static Analysis
  script:
  - pip install pylint
  - pylint -d C0301,C0114 *.py

test:
  stage: Test
  script:
  - pwd
  - ls -l
  - export PYTHONPATH="$PYTHONPATH:."
  - python -c "import sys;print(sys.path)"
  - pytest sonarqube $SONARQUBE_ARGUMENTS_NORMAL

after_script:
  - echo "End CI"

Stati c analisys (flake8, mypy, pylint) работает нормально, но У меня проблема с этапом тестирования, где я использую Pytest. В логе CI есть что:

 $ pytest sonarqube $SONARQUBE_ARGUMENTS_NORMAL
 ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
 pytest: error: unrecognized arguments: -Dsonar.host.url=http://127.0.0.0:8000 -Dsonar.login=my_login -Dsonar.password=my_password --stacktrace

Можете ли вы дать мне какую-то идею, что я делаю неправильно? Я делаю то же самое в android проекте с Gradle, и это прекрасно работает.

./gradlew test sonarqube $SONARQUBE_ARGUMENTS_NORMAL
...