Heading image


  1. Familiarity with Pipenv. See here for my post on Pipenv.
  2. Read Python Unit Testing With PyTest if you are unfamiliar with Python.

Getting started

Let’s clone the original PyTest repo in hello-pytest-github-actions.

Adding the test script

In of the Pipfile, we want to add a [scripts] section to add a test script:

Adding the GitHub action

We are now ready to add the GitHub action. Within the .github/workflows/pytest.yml file that we created earlier, add the following:

  1. Creating a job call PyTest.
  2. Running this job on a push event to the repository.
  3. Running the job on ubuntu-latest.
  4. Setting a custom timeout of 10 minutes (albeit this is overkill, feel free to omit).
  5. Setting up the Python environment for the latest in version 3.x.
  6. Install pipenv and wheel.
  7. Install dependencies with a cache set to be the hash of the lockfile.
  8. Running the test suite that we setup the command and tested before.
Action working as expected


Today’s post demonstrated how to use GitHub actions to test Python code on a push to the remote repository. We used the pytest testing framework to test our code.

Resources and further reading

  1. The ABCs of Pipenv
  2. Pipenv
  3. GitHub Actions
  4. Creating a Python GitHub Action
  5. Final project
  6. Python Unit Testing With PyTest




Senior Engineer @ UsabilityHub. Formerly Culture Amp.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

M_STORE — An e-commerce site for my ALX/Holberton portfolio project

Set Control: Relevant Values

Insights on StackOverFlow Survey Results

Make Designers Part of Scrum Teams (Agile Software Development)

MVVM Architecture

AWS Security Best Practices in Creating and Managing Multiple Accounts

Welcome to Jon Portella’s Medium profile

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dennis O'Keeffe

Dennis O'Keeffe

Senior Engineer @ UsabilityHub. Formerly Culture Amp.

More from Medium

A quick method to cross-cluster data copying with a Python script

Quick Tip: Writing newline character to JSON file in Python

Leverage your Python unit tests with Nox and Docker

My First Programming Project: Text-based Hangman Game using Python