I have a python package, and I am using poetry
for dependency management and packaging.
In my local environment, I am using tox
to test the package in multiple python version.
How can I use GitHub actions to test my package, everytime there is a push or pull request ?
Things that I have tried:
pip
and requirements.txt
, but I am using poetry)pip
, which is not recommended by poetry, as it can cause conflict with my application dependencies, see issue )pytest
in every matrix (of github actions), this action seems to defeat the purpose of tox)I want to test my python code in gh-actions.
in my situation, what should I actually use ?
what are the best practices ? and most optimum tool
The beauty of tox
is that you can run it both locally and on CI.
You have a high chance of a successful CI when it passes locally, and also you only need to define the test requirements and the test setup once, in one file.
To do so, I recommend using the mentioned tox-gh-actions
.
I applied this pattern to dozens of repositories with success.
I recommend the following blog post which gives a great introduction to this setup:
https://hynek.me/articles/python-github-actions/
You can have a look at the tox.ini and the gh action config file for e.g. Flask-Reuploaded.
As to your question about running pytest in every matrix... the drawback here is that you need to take care of the test setup yourself, and you have to define everything at two places, tox.ini
for local testing and in the yaml config for gh actions.