Home > Backend Development > Python Tutorial > Automate testing with Github Actions

Automate testing with Github Actions

Patricia Arquette
Release: 2024-12-04 10:42:14
Original
387 people have browsed it

Automate testing with Github Actions

I assume you have a Python project, but you can adapt it to any languages / frameworks.

Create the .github/workflows folder and the yml file at the root of your project.

mkdir -p .github/workflows && touch .github/workflows/testing.yml
Copy after login

The testing.yml file:

name: test
on:
  pull_request:
    branches:
      - main
      # Add any branch

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python 3.x
        uses: actions/setup-python@v4
        with:
          python-version: "3.10"
          architecture: "x64"
      - name: Display Python version
        run: python -c "import sys; print(sys.version)"

      - name: Install dependencies
      # Install necessary dependencies to run the tests
        run: |
          python -m pip install --upgrade pip
          pip install poetry
          poetry install

      - name: Run Tests
      # Add command to run test
        run: |
          make test

Copy after login

Each time a PR is made to the main branch, the tests will run.
I am using a Python project, but you can easily find YAML template files for any language or framework.
You can then add a branch rule on GitHub to prevent merging a PR if the tests fail.

The above is the detailed content of Automate testing with Github Actions. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template