Travis

Use Python with Travis CI

The following is a guide to getting started with Travis CI using Python.

Prerequisite #

In the root of your Python project, create a file named .travis.yml. This file defines how Travis CI builds and tests your project.

Specify the Language and Version #

Add the following code to let Travis CI know you are working with Python and the versions you want to test against:

language: python
python:
  - "3.8"
  - "3.9"
  - "3.10"

Install Build Dependencies #

Travis CI will automatically run commands to install your dependencies. In our example, a requirements.txt file manages dependencies.

 install:
  - pip install -r requirements.txt

Define the Test Command #

Specify a command to run your tests. The example below uses pytest:

 script:
  - pytest

Commit and Push #

Once you’ve configured your .travis.yml file, push it to your GitHub repository, and Travis CI will trigger the build and test process automatically. The following is the complete example:

language: python
python:
  - "3.8"
  - "3.9"
  - "3.10"
install:
  - pip install -r requirements.txt
script:
  - pytest

Further Reading #

For more information on Python projects, see: