📜 ⬆️ ⬇️

Tic Tac Toe, part 7: pytest and Travis CI

Tic Tac Toe: Content Cycle

In this article, we ’ll look at Continuous Integration through the use of Travis CI .


Create an account on GitHub if you do not already have one. Create a new repository with any name, for example, test-travis .


Log in to Travis CI using your GitHub account. Link your account to your GitHub account. Select the test-travis repository .


On GitHub, add the .travis.yml file to the repository with the following contents:


language: python script: - pytest 

Travis CI will automatically start building the project. In Travis CI, through Dashboard, go to the project’s build page, observe the build process and look at the result.
We see that not a single test was completed, because they simply are not in our repository.


Add test_sample.py to our GitHub repository. Copy it from here .


 # content of test_sample.py def inc(x): return x + 1 def test_answer(): assert inc(3) == 5 

Go to Travis CI on the project build page and see that the build process has begun. The test, as expected, did not pass.


We fix test_sample.py , go to Travis CI on the project build page, we see that the test passed.


Homework

Try taking the project from the Tic Tac Toe article , part 4: Interacting with the Flask backend using HTTP . You can simply fork from this repository: https://github.com/nomhoi/tic-tac-toe-part4 . Add some tests for Python and JavaScript scripts, add the .travis.yml file. Test setup documentation for Python: https://docs.travis-ci.com/user/languages/python/ , for JavaScript: https://docs.travis-ci.com/user/languages/javascript-with-nodejs / . I will also try and post a link to the repository here later.


Conclusion

To use the continuous integration technology from all of our movements, it was necessary to add the .travis.yml file to the repository, log in to the Travis CI service and select the repository there. In the future, there will be efforts only to properly configure the .travis.yml configuration file.


If there is only one developer, then you can run tests on your local computer. But if the project is written by a team, then it is more convenient to run tests after each push to a common repository. Tests will be performed by the system of continuous integration automatically after each push'a in the general repository.


In the following articles we will consider Continuous Delivery.


')

Source: https://habr.com/ru/post/461905/


All Articles