【问题标题】:Runing Django tests with Jenkinsfile (with docker)使用 Jenkinsfile(使用 docker)运行 Django 测试
【发布时间】:2023-03-23 13:13:01
【问题描述】:

我有一个在 Docker 中运行的 Django 应用程序(Postgres、Nginx 和 Jenkins 也在 docker 中), 我想通过创建管道来运行测试

问题是每次我用 python app/manage.py test 运行它(因为 jenkisnfile 在名为“app”的项目文件夹之外),它只是运行一个空的 test.py文件(所以它返回 0 测试成功)即使我有实际测试。

如果我直接从终端运行测试,它就可以工作

$ docker-compose run web python manage.py test
Creating proj1_web_run ... done
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..........
----------------------------------------------------------------------
Ran 10 tests in 0.229s

OK
Destroying test database for alias 'default'..

这里是 Jenkins 文件

      pipeline {
        agent {
            docker { image 'python:3.9' }
        }
        stages {
            stage('Build') {
                steps {
                    sh 'pip install -r requirements.txt'
                }
            }

            stage('Test') {
                steps {
                    sh 'python app/manage.py test'
                }
            }

            stage('Deploy') {
                steps {
                    sh 'echo not yet...'
                }
            }
        }
    }

Jenkins 控制台输出中的消息

+ python app/manage.py test
System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

非常感谢您的帮助

【问题讨论】:

    标签: django jenkins


    【解决方案1】:

    这与 jenkins 或 docker 无关。 Django 测试运行程序搜索当前目录(如果是 python 包,则搜索子目录)。可以先cd app,也可以指定目录:

    python app/manage.py test ./app

    【讨论】:

      猜你喜欢
      • 2015-12-01
      • 2022-06-20
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多