AI Hints
CI/CD with GitHub Actions · Lesson 25 of 138

Running Tests in CI

The heart of CI.

⏱ 2 min read▶ Video at 28:07🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Now we put it all together. ACI workflow that checks out the code, sets up Python, installs the requirements, and runs the tests, on every push to main, and on every pull request.

Running Tests in CI
From the video: Running Tests in CI
  • Put it all together
  • Checkout, setup, install, test
  • On every push and PR

The CI workflow

This is the workflow we read earlier, and it's the one we'll grow through the course. Two uses steps prepare the machine. Then two run steps do the real work. Installing the dependencies, and running pytest. If pytest fails, the whole workflow fails.

.github/workflows/ci.ymlyaml
name: CI

on:
  push:
    branches: [main]
  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 dependencies
        run: pip install -q -r requirements.txt
      - name: Run tests
        run: pytest -q

A green run

Here's the run. The two uses steps are marked GitHub only, because they need GitHub's servers. Pip, with dash Q for quiet, finds the requirements already installed, so it prints nothing. Pytest runs three tests, and they all pass. The job succeeded. On GitHub, this commit would get a green tick.

Terminal
run-steps .github/workflows/ci.yml
Workflow: CI  (event: push, branch: main)
Job: test
  ↷ uses actions/checkout@v4  (GitHub only)
  ↷ uses actions/setup-python@v5  (GitHub only)
  ✓ Install dependencies
  ✓ Run tests
      ...                                                                                [100%]
      3 passed in 0.01s
  Job succeeded

Summary

Our CI workflow installs the requirements and runs the tests on every push and pull request. Next, reading the logs properly.

Key takeaways
  • checkout + setup
  • pip install
  • pytest
Next up: Reading the Logs — what happened, step by step