I have Python package with setup.py
. It has regular dependencies declared in install_requires
and development dependencies declared in tests_require
, e.g. flake8
.
I thought pip install -e .
or running python setup.py test
will also install my development dependencies and they'll be available. However, apparently they're not and I struggle to setup my Travis CI build right.
install:
- "pip install -e ."
script:
- "python setup.py test"
- "flake8"
Build configured as above will fail, because flake8
will not be found as a valid command. I also tried to invoke flake8
from inside of the python setup.py test
command (via subprocess
), but also without success.
Also I hate the fact that flake8
can't be easily made integral part of the python setup.py test
command, but that's another story.
Download Dependencies OnlyUse the pipdeptree utility to gather a list of all dependencies, create a requirements. txt file listing all the dependencies, and then download them with the pip download command. Get the list of dependencies for a package from the setup.py file.
Pip will not flag dependency conflicts. As a result, it will happily install multiple versions of a dependency into your project, which will likely result in errors. One way to avoid dependency conflicts is to use an alternative Python package manager, like conda, poetry or ActiveState's State Tool.
Step 1: Download the get-pip.py (https://bootstrap.pypa.io/get-pip.py) file and store it in the same directory as python is installed. Step 2: Change the current path of the directory in the command line to the path of the directory where the above file exists. Step 4: Now wait through the installation process. Voila!
The more direct answer is that pip install
will not install tests_require
, intentionally separating runtime requirements from test requirements. python setup.py test
creates a virtualenv-like environment to run the tests in, un-doing this afterwards. flake8
is thus unavailable once it is done.
Flake8 has setuptools integration and also integrates with pytest if you use that. pytest itself also integrates with setuptools.
I prefer to keep most of the configuration in tox.ini
and rely on it to install and run what is to be run. For testing I use pytest
(the solution can be modified to use other testing frameworks easily).
Following files are used:
tox.ini
: automates the test.travis.yml
: instructions for Travissetup.py
: installation script to install the package to testtest_requirements.txt
: list of requirements for testingtox.ini
[tox]
envlist = py{26,27,33,34}
[testenv]
commands =
py.test -sv tests []
deps =
-rtest-requirements.txt
.travis.yml
sudo: false
language: python
python:
- 2.6
- 2.7
- 3.3
- 3.4
install:
- pip install tox-travis
script:
- tox
test_requirements.txt
Just ordinary requirements file whith what ever you need in there (e.g. flake8
, pytest
and other dependencies)
You may see sample at https://github.com/vlcinsky/awslogs/tree/pbr-setup.py
The fact it uses there pbr
, coverage
and coverall
is not relevant to my answer (it works with or without pbr).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With