[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: running tests against installed version of package



On 04/02/2016 09:41 AM, Tiago Ilieve wrote:
> Thomas,
> 
> On 31 March 2016 at 18:49, Thomas Goirand <zigo@debian.org> wrote:
>> Most of the time, you get by this doing:
>> PYTHONPATH=$(CURDIR) python -m pytest tests
> 
> Awesome tip! Just stumbled up on this one when imports where changed
> from relative to absolute and this tip properly fixed the matter.
> 
> Piotr,
> 
> On 31 March 2016 at 19:13, Piotr Ożarowski <piotr@debian.org> wrote:
>> this will test python2.7 only and will most probably ignore extensions, etc.
> 
> I've used the following workaround for this.
> 
> override_dh_auto_test:
>         PYTHONPATH=$(CURDIR) py.test
>         PYTHONPATH=$(CURDIR) py.test-3

Don't use py.test-FOO, as this is deprecated. Instead, use something
like this:

PYTHON3S:=$(shell py3versions -vr)

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
        @echo "===> Running tests"
        set -e ; set -x ; for i in 2.7 $(PYTHON3S) ; do \
		PYTHONPATH=. python$$i -m pytest ; \
	done
endif

Note that you can hardcode 2.7, as we will keep this version for Python2
basically forever (or until Python 2 completely dies), so it doesn't
really mater.

Having multiple version of Py3 supported also helps backporting from Sid
to Jessie, and also supports future version of Py3 (as Brian wrote).

Last, as Piotr wrote, PYTHONPATH=. isn't enough for non pure-python
stuff. In this type of case, there are other workarounds (which I can
tell if you need them). What I personally do is that I get things built
and installed within debian/tmp. That's the most easy way, a lot more
than double-guessing the build/* folder names. This also has the
advantage that the egg-info gets (re-)generated in the correct place. In
such case, you will want to do something like this:

python setup.py install --install-layout=deb \
	--root=$(CURDIR)/debian/tmp
PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python2.7/dist-packages \
	PYTHONPATH=. python -m pytest

Combine this with the loop for multiple version of Python above, and you
got (nearly) everything covered.

Hoping this helps,

Cheers,

Thomas Goirand (zigo)


Reply to: