python - GitHub Actions 没有获取 Django 测试

标签 python django docker continuous-integration github-actions

我想编写一个简单的 GitHub Action,在我推送到 GitHub 时运行我的 Django 应用程序测试。 GitHub 在推送时运行工作流,但出于某种原因,即使在本地运行 python ./api/manage.py test 可以正常工作,它也不会选择任何测试。

作业摘要的运行测试部分显示了这一点:

1s
Run python ./api/manage.py test

System check identified no issues (0 silenced).
----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
1s
2s
0s

作为背景,我的本地设置使用的是 docker-compose,每个应用程序都有一个 dockerfile。 Django 应用程序是 API。我只想在推送时运行 Django 测试。

我遇到过 GitHub 服务容器,我认为它们可能是必需的,因为 django 需要一个 postgres 数据库连接来运行它的测试。

我是 GitHub Actions 的新手,所以任何方向都将不胜感激。我的直觉是它应该比这更简单,但下面是我当前的 .github/workflows/django.yml 文件:

name: Django CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  tests:

    runs-on: ubuntu-latest
    container: python:3
    
    services:
      # Label used to access the service container
      db:
        # Docker Hub image
        image: postgres
        # Provide the password for postgres
        env:
          POSTGRES_PASSWORD: password
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    
    steps:
      # Downloads a copy of the code in your repository before running CI tests
      - name: Check out repository code
        uses: actions/checkout@v2

      # Performs a clean installation of all dependencies
      - name: Install Dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r api/requirements.txt

      - name: Run Tests
        run: |
          python ./api/manage.py test
        env:
          # The hostname used to communicate with the PostgreSQL service container
          POSTGRES_HOST: postgres
          # The default PostgreSQL port
          POSTGRES_PORT: 5432

最佳答案

不知道你有没有自己解决,如果有请分享你的解决方法。但是,我在做与您相同的事情时遇到的情况是,我必须指定要测试的应用才能正常工作。

例如,如果您的应用名为“testapp”,您需要执行以下操作:

 run: |
          python ./api/manage.py test testapp 

关于python - GitHub Actions 没有获取 Django 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69131314/

相关文章:

python - 排列:返回第k个排列

django - 我应该放弃 Google App Engine 吗?

python - django-allauth:如何修改电子邮件确认网址?

c# - error MSB3103 : Invalid Resx file. 找不到指定的模块

postgresql - 使用本地数据库列出 docker 数据库

python - 如何取一个数字并找到它的字母位置python

python - leastsq 的置信区间适合 scipy python

python 嵌入 C : define the python script as a C string?

python - 如何在 Django 1.6 中使用 ModelForms 避免 "record already exists"表单验证错误?

linux - 从私有(private) docker 注册表下载 docker 镜像后可以重新分发吗?