Continuous Integration with Tests

A snippet showing how to run Django tests in CI/CD workflows.


# models.py

from django.db import models

class Job(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
      

# admin.py

from django.contrib import admin
from .models import Job

@admin.register(Job)
class JobAdmin(admin.ModelAdmin):
    list_display = ("created_at",)
      

# Result (GitHub Actions workflow example: .github/workflows/tests.yml)

name: Django Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: {python-version: '3.12'}
      - name: Install deps
        run: pip install -r requirements.txt
      - name: Run tests
        run: python manage.py test
      
Explanation:
  • Run tests in CI on every push/PR to catch regressions early.
  • Cache dependencies and fail the build on test failures.
  • Category Testing
  • Total Views 858
  • Last Modified 20 March, 2026
  • Tags #testing #ci #automation #django
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.