Use Travis CI to do unit test everytime a code is pushed

Hello,

I’m new to this community, so please be kind if I make any mistake.

I’m working on a python project which takes a file as an argument. Now that the project is growing larger, Automating unit testing would help run the project efficiently.

Goal is to get a unit test results on Github by travis CI everytime a code is pushed. (even better if it can be triggered at a code review request)

Syntax of project execution - python3 main.py -f input.file

Can travis CI support input file as a parameter?
Can I run multiple instances of the unit test where it runs main.py instances on 10 different files?
Where should I be hosting the input files?

Hope to get some answers to this

Yes, running tests for every push is exactly the idea behind continuous integration (CI).

Can travis CI support input file as a parameter?

Yes, Travis CI can indeed run whatever commands you like. For example:

language: python

python:
  - "3.10"

# command to run tests
script:
  - python3 main.py -f input.file

Can I run multiple instances of the unit test where it runs main.py instances on 10 different files?

Yes, one way is to do it something like this. It will do one after the other, and stop as soon as the first one fails.

language: python

python:
  - "3.10"

# command to run tests
script:
  - python3 main.py -f input.file
  - python3 main.py -f input.file2
  - python3 main.py -f input.file3

If you want to run them each in their own, seperate “job”, use environment variables. This way, if one fails, only that fails, and the others will still be run. For example:

language: python

python:
  - "3.10"

env:
- TEST_FILE=input.file
- TEST_FILE=input.file2
- TEST_FILE=input.file3

# command to run tests
script:
  - python3 main.py -f $TEST_FILE

Where should I be hosting the input files?

The easiest thing would be to put them in your GitHub repository. Travis CI clones your repo, and the files will be available for use.

1 Like

Is there any limitation to how big the file can be?
My input file size ranges from 500MB to 20GB.