首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >GiltLab CI/CD测试失败

GiltLab CI/CD测试失败
EN

Stack Overflow用户
提问于 2022-09-03 08:51:44
回答 1查看 138关注 0票数 0

我想用一个Django项目在带有CI/CD的Gitlab上运行一些测试。本地pc上的测试工作正常,我的工作测试管道在这些测试中总是失败。我得到了一个SyntaxError。

在这里,当测试失败时,我在管道中遇到的脚本失败:

代码语言:javascript
运行
复制
Running with gitlab-runner 15.3.0~beta.42.gdb7789ca (db7789ca)
  on blue-3.shared.runners-manager.gitlab.com/default zxwgkjAP
Preparing the "docker+machine" executor
00:06
Using Docker executor with image ruby:2.5 ...
Pulling docker image ruby:2.5 ...
Using docker image sha256:27d049ce98db4e55ddfaec6cd98c7c9cfd195bc7e994493776959db33522383b for ruby:2.5 with digest ruby@sha256:ecc3e4f5da13d881a415c9692bb52d2b85b090f38f4ad99ae94f932b3598444b ...
Preparing environment
00:01
Running on runner-zxwgkjap-project-39068925-concurrent-0 via runner-zxwgkjap-shared-1662191947-427cb239...
Getting source from Git repository
00:02
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/XXX/Deploy_django_application_to_server/.git/
Created fresh repository.
Checking out 51c8456f as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
Using docker image sha256:27d049ce98db4e55ddfaec6cd98c7c9cfd195bc7e994493776959db33522383b for ruby:2.5 with digest ruby@sha256:ecc3e4f5da13d881a415c9692bb52d2b85b090f38f4ad99ae94f932b3598444b ...
$ echo "Running unit tests..."
Running unit tests...
$ python manage.py test app_users.tests.CustomUserTests
  File "manage.py", line 17
    ) from exc
         ^
SyntaxError: invalid syntax
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

*我的..gitlab ci.yml的脚本是:

代码语言:javascript
运行
复制
    stages:          # List of stages for jobs, and their order of execution
      - build
      - test
      - deploy
    
    build-job:       # This job runs in the build stage, which runs first.
      stage: build
      script:
        - echo "Compiling the code..."
        - apt update
        - echo y | apt install python3-pip
        - pip3 install --upgrade pip
        - pip3 install -r requirements.txt
    
    django-tests:
      stage: test
      script:
        - echo "Running unit tests..."
        - python manage.py test app_users.tests.CustomUserTests
        - python manage.py test app_manage.tests.BasePageTestCase
        - python manage.py test app_manage.tests.TermesPageTestCase
        - python manage.py test app_manage.tests.IndexTestCase
        - python manage.py test app_manage.tests.SearchTestCase
    
    lint-test-job:   # This job also runs in the test stage.
      stage: test    # It can run at the same time as unit-test-job (in parallel).
      script:
        - echo "Linting code... This will take about 10 seconds."
        - echo "No lint issues found."

*我知道它来自我的manage.py文件第17行,但是我--这是manage.py的默认设置。我将Django项目从Pycharm直接推到了GitLab。我有一个用于此项目的Postgresql数据库。我在Django项目中使用TestCase和SimpleTestCase。

我被困在GitLab CI /CD的测试工作:-(。谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-09-03 15:52:32

您的坞映像使用python2.7作为python可执行文件。我通过以下操作获得了这些信息:

代码语言:javascript
运行
复制
$ docker run -it --rm --entrypoint bash ruby:2.5
root@c4cf25791396:/# python --version
Python 2.7.16
root@c4cf25791396:/# python3 --version
Python 3.7.3

Django与python2.7不兼容(参见这里 )。

您应该使用使用python3作为默认python解释器的停靠器映像,或者直接调用python3可执行文件。

代码语言:javascript
运行
复制
    django-tests:
      stage: test
      script:
        - echo "Running unit tests..."
        - python3 manage.py test app_users.tests.CustomUserTests
        - python3 manage.py test app_manage.tests.BasePageTestCase
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73590883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档