簡體   English   中英

GitHub Actions 不接受 Django 測試

[英]GitHub Actions not picking up Django tests

我想編寫一個簡單的 GitHub 操作,在我推送到 GitHub 時運行我的 Django 應用程序的測試。 GitHub 在推送時運行工作流,但由於某種原因,它不接受任何測試,即使在本地運行python ./api/manage.py test可以。

作業摘要的Run tests部分顯示了這一點:

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 db 連接來運行它的測試。

我是 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 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM