gitlab

testdriven.io flask-tdd-docker course chapter 15 pipeline stage test ERROR: Job failed: exit code 1


I am following python/flask/docker tutorial . Everything worked perfectly until I pushed to GitLab the pipeline stage builds fine then fails on test stage:

  stage: test
  image: $IMAGE:latest
  services:
    - postgres:latest
  variables:
    POSTGRES_DB: users
    POSTGRES_USER: runner
    POSTGRES_PASSWORD: runner
    DATABASE_TEST_URL: postgres://runner:runner@postgres:5432/users
  script:
    - python3.8 -m venv env
    - source env/bin/activate
    - pip install -r requirements.txt
    - pip install black flake8 isort pytest
    - pytest "project/tests" -p no:warnings
    - flake8 project
    - black project --check
    - isort project/**/*.py --check-only

The pipeline test logs:

$ pytest "project/tests" -p no:warnings
============================= test session starts ==============================
platform linux -- Python 3.8.1, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: /builds/piccoloa/flask-on-docker/project/tests, configfile: pytest.ini
collected 30 items
project/tests/test_config.py ...                                         [ 10%]
project/tests/test_ping.py .                                             [ 13%]
project/tests/test_users.py .............                                [ 56%]
project/tests/test_users_unit.py .............                           [100%]
============================== 30 passed in 0.41s ==============================
$ flake8 project
$ black project --check
would reformat /builds/piccoloa/flask-on-docker/project/api/users.py
would reformat /builds/piccoloa/flask-on-docker/project/tests/test_users.py
would reformat /builds/piccoloa/flask-on-docker/project/tests/test_users_unit.py
Oh no! 💥 💔 💥
3 files would be reformatted, 10 files would be left unchanged.
Cleaning up file based variables
00:00
ERROR: Job failed: exit code 1

Found this but don't know how to fix or if it ralates to problem. "Adjust your threshold or improve coverage" mentioned in this GitLab Issue. I don't get any errors when I run the test on localhost?


Solution

  • I think you're on the right track. It seems to me that your CI is failing because black is finding files to reformat. It is possible that the version of black running in your CI is different than the one that runs locally, and therefore suggests new/different changes.

    You could look through the output of your Gitlab pipeline for the version of black that is used there. If the version doesn't match your local version of black, try running your files locally through the version of black used by Gitlab, and then committing those changed files to your repo to trigger your CI.