Short Travis getting started with python, quick and dirty.
A lot of tutorials are available about this topic, so I will give you only the fundamentals to effectively setup your first COMPLETE travis build pass with python.
Before to start with this tutorial you should know that you will need to make code tests by yourself in order to use Travis. If you don't know what tests are, than you better read a little bit about it at the end of this tutorial. Anyway Keep Calm and Carry on, you will make your first build pass at the end of this.
- Create a new Github repository into your profile, say tutorials-travis_testing_python.
Now you should have the repository YOURNAME/tutorials-travis_testing_python/.
( compare with this repository ) - Create a new python module, say test_testami.py (❗️ it must be named with a prefix test_) and write into it:
- a python function funzione
- ❗️ a pytest (python testing framework) function test_funzione that will assert the output of funzione
( compare with test_testami.py in this repository )
- Create the .travis.yml file containing the configuration about Travis behaviour.
( compare with .test.yml in this repository ) - Create a requirements.txt file with the required modules for your module to run. If it needs no other modules let it empty, but create it anyway.
- Go to Travis CI
- Sign Up or Sign In with your Github account
- From you Travis console, reachable at https://travis-ci.com/profile/**YOURGITHUBNAME**, click on Manage Repositories on Github and access with your Github password. Now you should be in your Travis CI Github Manager and you should be able to see in particular two sections: Permissions and Repository access.
- Go to Repository access and make your choice. I prefer to Select Repositories, specifying tutorials-travis_testing_python.
- Select Approve and Install. Now on, Travis will launch a build at every commit you will do to your repository.
- Yes, everyone, automatically.
- Go back to your Travis CI console and select Sync account.
- From your Travis CI console you should see under Repositories tab the name of the repository you just added, tutorials-travis_testing_python, so click on it to go to the Travis CI branch related to it. From there you can see the builds.
- Go to your Github repository and commit whatever you want. For example you can edit your readme.
- Jump to your Travis CI branch and watch it working. If you followed everything well you should see the beautiful exit line
=========================== 1 passed in 0.02 seconds ===========================
The command "pytest" exited with 0.
Done. Your build exited with 0.
- Read again 2.6
- Go editing your test_testami.py file changing the returned value in a wrong way, for instance concatenating a str with a int and see what happens
- Add your Travis CI Passing Badge to your README.md! You can do it reading this easy guide: https://docs.travis-ci.com/user/status-images/.
...or you can just add[](https://travis-ci.com/YOURGITHUBNAME/travis_testing_python)
but maybe it will not be enough... (I warmly suggest you to read the guide, it's only 2 steps!).
Tests are done. Enjoy your brand new badge
BTW... you can fork this repository and make it run instantly after connected with your Travis CI