{"id":307,"date":"2022-01-10T00:00:00","date_gmt":"2022-01-10T00:00:00","guid":{"rendered":"https:\/\/tac.debuzzify.com\/?p=307"},"modified":"2023-06-21T14:25:15","modified_gmt":"2023-06-21T14:25:15","slug":"python-auto-run-tests","status":"publish","type":"post","link":"https:\/\/www.the-analytics.club\/python-auto-run-tests\/","title":{"rendered":"How to Run Python Tests on Every Commit Using GitHub Actions"},"content":{"rendered":"\n\n\n

It’s easy to avoid bugs than fix them.<\/p>\n\n\n\n

Testing is a critical component of every software project. Among several different types of software testing, some need to run at the time of every commit. For instance, developers should run unit tests to ensure their new change doesn’t contradict any previous ones.<\/p>\n\n\n\n

Yet, it is a burden to do it manually every time. It’s a dull, repetitive, but unavoidable task. It’s fun writing unit tests but not running them on every commit.<\/p>\n\n\n\n

Most dev teams use their continuous integration (CI) pipeline to trigger them. Thus, the developer doesn’t have to worry about not running them. GitHub Actions are one (and perhaps very popular) such option available to do this.<\/p>\n\n\n\n

In this post, I’ll walk you through the steps I follow to automate Python tests with GitHub Actions.<\/p>\n\n\n\n

Related: Python workflow automation with Prefect (A better Airflow)<\/em><\/a><\/strong><\/p>\n\n\n\n

How Python testing works on GitHub Actions<\/h2>\n\n\n\n

GitHub Actions has a pre-defined set of workflows you can plug and play. You could find one for popular frameworks such as Django<\/a> too. I recommend starting with one of them unless your project structure is unique.<\/p>\n\n\n\n

You can get there by clicking on the Actions tab on your GitHub repository page.<\/p>\n\n\n

\n
\"You<\/figure><\/div>\n\n\n

For this post, I will use the following example Python program and test.<\/p>\n\n\n\n