4

I have python application which I would like to test. This application is importing a lot of packages for example:

import time
import sys
.
.
.
import mypackage

Where mypackage is my own package.

When I start application everything works fine. However, as soon as I try to run tox to test it I will get the following error:

Collecting mypackage
Could not find a version that satisfies the requirement mypackage (from versions: )
No matching distribution found for mypackage

I understand that tox can't install mypackage dependency since it is not in pip. Do you know how to run tox on such application or how to install own packages with tox ?

Content of my tox.ini file:

[tox]
envlist = py36

[testenv]
deps =
    pytest
    coverage
    time
    sys
    mypackage
commands =
    python setup.py develop
    coverage erase
    coverage run -m pytest myapp/tests/
    coverage report --omit='.tox/*' 

3 Answers3

1

I think this should be possible in a number of ways if you're using pip instead of python setup.py:

  1. You can manually install the dependency by doing pip install /path/to/private/dependency, either before the installation of the package that is to be tested or in the same line. This has the (minor) advantage that you can also install your dependency in editable mode with -e.
  2. You can use the --find-links option for pip install as explained in answers to this question - this has the advantage that dependency processing itself is done automatically, you just specify your own package for installation and tell pip about where other stuff could be found. Importantly, this can also be specified using environment variables, so you don't have to have local paths hardcoded anywhere in your git repo.

Note: I'm not sure if option (2) works with just a git repo or only with proper archives... I remember having problems related to this with --find-links a while back.

smheidrich
  • 4,063
  • 1
  • 17
  • 30
0

Tox iterates over all packages described in deps and tries to install all of them with pip install. As described at pip installing packages page you can:

pip install /path/my/package

It means that deps section accepts not only packages from PyPI, but also your local packages specified by path.

Simply add the root path of your package with setup.py to deps section and it should work.

deps =
    pytest
    coverage
    time
    sys
    /projects/py/mypackage
Alexander Tyapkov
  • 4,837
  • 5
  • 39
  • 65
  • Are there any special gotchas here? I tried adding an entry in tox.ini deps with the absolute path to the directory with mypackage's setup.py file. But tox doesn't seem to invoke pip in a way to install that package. The error is `ERROR: code: could not install deps [pytest, coverage, pytest-cov, /Users/me/git/github/mywork/mypackage]; v = InvocationError('/Users/me/git/github/mywork/.tox/code/bin/python -m pip install pytest coverage pytest-cov mypackage', 1)` – chrisinmtown Jan 13 '22 at 18:08
0

pip install /path/to/mypackage should be inserted in commands instead of deps

The code should be like

[testenv]
deps = some external packages

commands = 
  pip install -e "path/to/mypackage"
  pytest {posargs}

you can also add your git repository as

pip install git+https://path/to/repo.git
panday1995
  • 11
  • 3