[arch-dev-public] Unit tests for python packages
anthraxx at archlinux.org
Wed Apr 18 10:49:45 UTC 2018
On April 18, 2018 11:53:01 AM GMT+02:00, Baptiste Jonglez <baptiste at bitsofnetworks.org> wrote:
>Does anyone have experience with unit tests for python packages? It's
>really useful to spot missing runtime dependencies, but it's a pain to
>Here is what I saw:
>1) just running "python -m unittest discover" or "nosetests" or
> in the check() function does not work, because the package is not yet
> installed (so all imports will fail)
>2) setuptools is supposed to have a unittest integration such that
> "python setup.py test" should work out of the box, but in my case it
> never finds any tests to run
>3) I've seen some more... "creative" solutions :)
>So far, the only working solution I found is playing with PYTHONPATH:
> cd "$srcdir/$pkgname-$pkgver/tests"
> export PYTHONPATH="$srcdir/$pkgname-$pkgver/src"
> python -m unittest discover
>But it's a hack, and it probably won't work with things like 2to3.
>Any better ideas?
If you use a build function there shouldn't be any problems like 2to3 while running tests, everything should be converted / build and generated for the use of tests.
For certain upstream test setups there won't be much you can do other then PYTHONPATH but as mentioned with a build function it should always work.
You can give python-pytest-runner a go, it does proper resolution while running "python setup.py test" but requires certain ways the whole test suites are wired.
More information about the arch-dev-public