How to make Travis CI to install Python dependencies declared in test_require?

I have a Python package with setup.py . It has regular dependencies declared in install_requires , and development dependencies declared in tests_require , for example. flake8 .

I thought pip install -e . or running python setup.py test also install my development dependencies and they will be available. However, apparently this is not the case, and I'm struggling to set up the correct Travis CI build.

 install: - "pip install -e ." script: - "python setup.py test" - "flake8" 

The assembly configured as above will fail because flake8 will not be found as a valid command. I also tried calling flake8 from within the python setup.py test command (via subprocess ), but also to no avail.

I also hate the fact that flake8 cannot easily be made an integral part of the python setup.py test command, but this is another story.

+5
source share
2 answers

I prefer to store most of the configuration in tox.ini and rely on it to install and run what should be running. For testing, I use pytest (the solution can be easily modified to use other test frameworks).

The following files are used:

  • tox.ini : automates verification
  • .travis.yml : instructions for Travis
  • setup.py : install a script to install the package for testing
  • test_requirements.txt : list of requirements for testing

tox.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 a regular requirements file you will ever need (e.g. flake8 , pytest and other dependencies)

You can see the sample at https://github.com/vlcinsky/awslogs/tree/pbr-setup.py

The fact that he uses pbr , coverage and coverall there is not relevant to my answer (he works with or without pbr).

+10
source

A more direct answer is that pip install will not install tests_require , deliberately separating run-time requirements from test requirements. python setup.py test creates a virtual-like environment for running tests without doing so after that. flake8 is thus not available after its completion.

Flake8 has setuptools integration , and also integrates with pytest if you use this. pytest also integrates with setuptools .

0
source

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