• Re: [RFH] Running Python tests that require the source to be installed

    From Andrey Rakhmatullin@21:1/5 to Sebastiaan Couwenberg on Thu Oct 24 13:10:01 2024
    On Thu, Oct 24, 2024 at 12:57:42PM +0200, Sebastiaan Couwenberg wrote:
    You may need to copy some additional files there, e.g.:

    export PYBUILD_BEFORE_TEST=cp -r {dir}/foo {dir}/bar {build_dir}
    export PYBUILD_AFTER_TEST=rm -rf {build_dir}/foo {build_dir}/bar

    Consider using pybuild.testfiels for this.

    --
    WBR, wRAR

    -----BEGIN PGP SIGNATURE-----

    iQJhBAABCgBLFiEEolIP6gqGcKZh3YxVM2L3AxpJkuEFAmcaKa4tFIAAAAAAFQAP cGthLWFkZHJlc3NAZ251cGcub3Jnd3JhckBkZWJpYW4ub3JnAAoJEDNi9wMaSZLh lGsP/0hLNxUVATvwQ4FU7ybkvA/WAfyyINO2E/7L2Y04OZQ69jDIS5djq+Wvw8qn ycm8Ko4eEuivisnlMkAb+qTLRUE4Xe0x/2zSMkrrqqNDQAfuYhZQOheEmREJyrRJ 2XUgTDAmMm4rnRig/jqsaLas4u9fvLkMynMhww/5VoB5IiK1LoCjUK2pxHsMo6p9 4kioiiyts0eM630zh1n4RHjRvzHzUOd4RtbKvI7LlI+3aOzHiZ2NeLdhlj6Gvoqp 7SFWDhZeCJPqT4/U8abqZe9oQojrclUS3lJzKn6mSdR6URjlTuXo4bcNWoZqdT58 4VVBvpoY/eq4Z3sMzHIX3+5IngCcwoM5fo3Lh5ou+2ABp6YsKrpwCTxblnZX+gax 1M/GQeZwXYI3sGL0cFhKCV6QZFTmKCjFeSwa//02cqjP4scktwdVq2p9h/wxaCfW XX7yfGsKk1+kBvmRGtT4OZzBDrzlWM7YnYoH8CWZJT61EOQ/gjmnABdD4unUSuCP VnCzZKJPYCx6SDbsAcL0Cf+QJEMl+ErQjq/En7bmpc9l3LMEEhsUaRAXnbCy1zKL YJclmOIu9LktsQPOjx5nBp17w72YcXkG9XZMZy4NtbqXlvDEiwmQYbt5zxmmIqUS 7tWWGR4B4aO6PdyVJwi+HtjlHS3Z4s8uF6uIGgn7GlFxvqS/
    =M9jz
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrey Rakhmatullin@21:1/5 to John Paul Adrian Glaubitz on Thu Oct 24 13:10:01 2024
    On Thu, Oct 24, 2024 at 12:44:45PM +0200, John Paul Adrian Glaubitz wrote:
    (Please CC as I'm not subscribed to debian-devel)

    (this is how I realized this is not debian-python@, consider using that
    for more relevant coverage)

    I am maintaining the package src:kiwi [1] which hasn't been updated in
    Debian for some time since upstream has added tests that only work when
    the package source is installed into the test environment, i.e. available through PYTHONPATH.

    I believe any or at least most Python unittests require the module being
    tested to be available in sys.path and pybuild already helps with that, by running tests in a directory with the package installed, is that not
    enough? What are the specific problems you have?

    I have tried to adjust the environment variables in debian/rules as follows and tried to invoke the testsuite from the test/unit subdirectory:

    export PYTHONPATH = $(CURDIR)

    $(CURDIR) is already in sys.path when running python -m.

    export PYBUILD_TEST_ARGS_python3 = cd {build_dir}; python{version} -m discover

    override_dh_auto_test:
    ifeq ($(filter nocheck nobench, $(DEB_BUILD_OPTIONS)),)
    /bin/sh -c "cd test/unit && pytest-3"
    You should use python* -m pytest (note that you need to run it for all supported Python versions.

    --
    WBR, wRAR

    -----BEGIN PGP SIGNATURE-----

    iQJhBAABCgBLFiEEolIP6gqGcKZh3YxVM2L3AxpJkuEFAmcaKX8tFIAAAAAAFQAP cGthLWFkZHJlc3NAZ251cGcub3Jnd3JhckBkZWJpYW4ub3JnAAoJEDNi9wMaSZLh VrMQAIeEsl0GAWx1piJjPQRvnwRloee5bT/AgJyONkxqgBi/+xjws/9gYRrcrGvz wMcet+K0pbjP6kVCqoJia9l+rEma4LYuUG/uFzEYbA8nHJnVAWcYkkO/h6L3z/pE kkj98GLnlyPPl+cmgcm4EMd4CPpzxTiFQenLowq0MVc1nfO5CwipE3AJCwgaNBmt RWaqL1G7w8c4r0T7UgIa0+1WokX4H7ksIn035oWVGJsKlFy/uXT5FtAgudLuEb7d H/0pKMjNQxdTf8U3YafyWUd4xzJWImIVsvT9q+pppc7T6T4vUs2HJ93to3D4S/qp vIWs71Y0r0Xfa9Jo8uHhJoIjlfny2HC2vcphX0QHftjpuO7HAiBbU6MzM58iXpvq PBFUqSyFb/K24b2QKz+sBMraw9r9e+wILapM6Ux8qGBXVOufTxV9hZ+zIKk02006 u2vo9kUvrs8fzl86bjd2GkAjTbnNe0DH764DshJ2j3NLq85S0U3isSAKZEC1P2lS /jTm7qkg0/5i+Mhk4YSp/hi8seE9gvI1qdyySko4trRBWaCoxfxgXf7p6HVgbW3k 9tvquwWVdsa4NjfV86IkSEz9hOpz+LDNMc1hPUkWqk9/MKokcWRSEdTRqc4S6RwM ZKVbbGqc5rQl/hbOOLdfngIMmXNhlJxktYWOfE3SJkQTjSEz
    =FEpB
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to All on Thu Oct 24 12:50:01 2024
    (Please CC as I'm not subscribed to debian-devel)

    Hello,

    I am maintaining the package src:kiwi [1] which hasn't been updated in
    Debian for some time since upstream has added tests that only work when
    the package source is installed into the test environment, i.e. available through PYTHONPATH.

    I have tried to adjust the environment variables in debian/rules as follows
    and tried to invoke the testsuite from the test/unit subdirectory:

    export PYTHONPATH = $(CURDIR)
    export PYBUILD_TEST_ARGS_python3 = cd {build_dir}; python{version} -m discover

    override_dh_auto_test:
    ifeq ($(filter nocheck nobench, $(DEB_BUILD_OPTIONS)),)
    /bin/sh -c "cd test/unit && pytest-3"
    endif

    However, that doesn't work and the tests still fail.

    Does anyone have a suggestion how to solve? I would like to update the kiwi package to the latest upstream version before the Trixie release.

    Adrian

    [1] https://salsa.debian.org/debian/kiwi

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer
    `. `' Physicist
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to Andrey Rakhmatullin on Thu Oct 24 13:20:01 2024
    Hi Andrey,

    thanks a lot for the fast and already helpful reply!

    On Thu, 2024-10-24 at 16:03 +0500, Andrey Rakhmatullin wrote:
    On Thu, Oct 24, 2024 at 12:44:45PM +0200, John Paul Adrian Glaubitz wrote:
    (Please CC as I'm not subscribed to debian-devel)

    (this is how I realized this is not debian-python@, consider using that
    for more relevant coverage)

    Duly noted!

    I am maintaining the package src:kiwi [1] which hasn't been updated in Debian for some time since upstream has added tests that only work when
    the package source is installed into the test environment, i.e. available through PYTHONPATH.

    I believe any or at least most Python unittests require the module being tested to be available in sys.path and pybuild already helps with that, by running tests in a directory with the package installed, is that not
    enough? What are the specific problems you have?

    I had to look it up and the mechanism used is called "entry_points". The kiwi package adds such entry_points and wants to test them in its testsuite.

    Thus, I need to figure out how to make those entry_points visible from the build environment so that the testsuite can find and test them.

    Is there any other Debian Python package that uses entry points?

    I have tried to adjust the environment variables in debian/rules as follows and tried to invoke the testsuite from the test/unit subdirectory:

    export PYTHONPATH = $(CURDIR)

    $(CURDIR) is already in sys.path when running python -m.

    export PYBUILD_TEST_ARGS_python3 = cd {build_dir}; python{version} -m discover

    override_dh_auto_test:
    ifeq ($(filter nocheck nobench, $(DEB_BUILD_OPTIONS)),)
    /bin/sh -c "cd test/unit && pytest-3"
    You should use python* -m pytest (note that you need to run it for all supported Python versions.

    OK, thanks.

    Adrian

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer
    `. `' Physicist
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Timo =?utf-8?Q?R=C3=B6hling?=@21:1/5 to All on Fri Oct 25 22:30:02 2024
    Hi Adrian,

    * John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
    * [2024-10-24 13:11]:
    I had to look it up and the mechanism used is called
    "entry_points". The kiwi package adds such entry_points and wants
    to test them in its testsuite.

    Thus, I need to figure out how to make those entry_points visible
    from the build environment so that the testsuite can find and test
    them.

    Is there any other Debian Python package that uses entry points?
    I ran into this issue with old-style setuptools packages (i.e.,
    packages with a setup.py); AFAIK the entry_points mechanism needs
    valid egg-info or dist-info metadata in the PYTHONPATH. My
    workaround was


    export PYBUILD_BEFORE_TEST=\
    {interpreter} setup.py egg_info; \
    cp -r {dir}/src/*.egg-info {build_dir}

    export PYBUILD_AFTER_TEST=\
    rm -r {dir}/src/*.egg-info {build_dir}/*.egg-info


    Cheers
    Timo


    --
    ⢀⣴⠾⠻⢶⣦⠀ ╭────────────────────────────────────────────────────╮
    ⣾⠁⢠⠒⠀⣿⡁ │ Timo Röhling │
    ⢿⡄⠘⠷⠚⠋⠀ │ 9B03 EBB9 8300 DF97 C2B1 23BF CC8C 6BDD 1403 F4CA │
    ⠈⠳⣄⠀⠀⠀⠀ ╰────────────────────────────────────────────────────╯

    -----BEGIN PGP SIGNATURE-----

    iQIzBAEBCgAdFiEEmwPruYMA35fCsSO/zIxr3RQD9MoFAmcb/VkACgkQzIxr3RQD 9Mpe8xAAytle51oMrNd6UaEV1TuJfmBKr2IX2Ua9dukt5QS31LfbLvwEfC/l4130 7NPeQPGRIy4AcNPPcUxrI/LsF398aE4tQcToDa0aoT8y7ZzqQgBhM983Fi7Crr7M FYggjqwktROWybII3RVPn3KYwvtbLkmxi2EPOIGr3kUa1Wld8dljyuL4rEf6Hbf5 cMBefzduts9KyltRO69QXus2kfq7QLiKrijXYxQ/bHZnTWCuBnKk7rqOg02UW25n raUMHEhdCPBLDZ7gIsYsryOuqOdHOj1NTKpDp1mFbW/qW2qV3JcsePzIv63Lox6H mFJXDm1B7RK7eYnn8xD92115OnRpMzTgW1ohO6r+YeL
  • From Stefano Rivera@21:1/5 to All on Sat Oct 26 04:50:01 2024
    Hi John (2024.10.24_10:44:45_+0000)
    I am maintaining the package src:kiwi [1] which hasn't been updated in
    Debian for some time since upstream has added tests that only work when
    the package source is installed into the test environment, i.e. available through PYTHONPATH.

    If it actually needs the .dist-info to be on path (fully installed), you
    can try runnig the tests under tox. That's probably what the upstream
    does.

    tox tests in Debian package builds are a little different because we use --system-site-packages virtualenvs, but they can be a good way to deal
    with this.

    Stefano

    --
    Stefano Rivera
    http://tumbleweed.org.za/
    +1 415 683 3272

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to Stefano Rivera on Sat Oct 26 10:50:01 2024
    Hello Stefano,

    On Sat, 2024-10-26 at 02:45 +0000, Stefano Rivera wrote:
    If it actually needs the .dist-info to be on path (fully installed), you
    can try runnig the tests under tox. That's probably what the upstream
    does.

    tox tests in Debian package builds are a little different because we use --system-site-packages virtualenvs, but they can be a good way to deal
    with this.

    Can you name any package using this mechanism so I can have a look?

    I'm not really experienced with tox, so it would be great to have some
    guidance in the form of sample code.

    Adrian

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer
    `. `' Physicist
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to All on Sat Oct 26 10:20:01 2024
    Hi Timo,

    On Fri, 2024-10-25 at 22:19 +0200, Timo Röhling wrote:
    I ran into this issue with old-style setuptools packages (i.e.,
    packages with a setup.py); AFAIK the entry_points mechanism needs
    valid egg-info or dist-info metadata in the PYTHONPATH. My
    workaround was


    export PYBUILD_BEFORE_TEST=\
    {interpreter} setup.py egg_info; \
    cp -r {dir}/src/*.egg-info {build_dir}

    export PYBUILD_AFTER_TEST=\
    rm -r {dir}/src/*.egg-info {build_dir}/*.egg-info

    Thanks, this is what I was looking for. I will give this a try.

    Adrian

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer
    `. `' Physicist
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to John Paul Adrian Glaubitz on Sat Oct 26 11:10:01 2024
    Hi Timo,

    On Sat, 2024-10-26 at 10:15 +0200, John Paul Adrian Glaubitz wrote:
    On Fri, 2024-10-25 at 22:19 +0200, Timo Röhling wrote:
    I ran into this issue with old-style setuptools packages (i.e.,
    packages with a setup.py); AFAIK the entry_points mechanism needs
    valid egg-info or dist-info metadata in the PYTHONPATH. My
    workaround was


    export PYBUILD_BEFORE_TEST=\
    {interpreter} setup.py egg_info; \
    cp -r {dir}/src/*.egg-info {build_dir}

    export PYBUILD_AFTER_TEST=\
    rm -r {dir}/src/*.egg-info {build_dir}/*.egg-info

    Thanks, this is what I was looking for. I will give this a try.

    I just realized that this doesn't work because kiwi doesn't have a setup.py anymore but just uses pyproject.toml. Do you know how it works in this case?

    Adrian

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer
    `. `' Physicist
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to John Paul Adrian Glaubitz on Sat Oct 26 11:20:01 2024
    On Sat, 2024-10-26 at 11:08 +0200, John Paul Adrian Glaubitz wrote:
    I just realized that this doesn't work because kiwi doesn't have a setup.py anymore but just uses pyproject.toml. Do you know how it works in this case?

    OK, I just remove every custom override and let debhelper and pybuild just do it's
    magic. Unfortunately, it turns out that the package now requires pytest_container
    which doesn't exist in Debian.

    *sigh*

    Adrian

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer
    `. `' Physicist
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefano Rivera@21:1/5 to All on Sat Oct 26 18:40:01 2024
    Hi John (2024.10.26_08:45:15_+0000)
    tox tests in Debian package builds are a little different because we use --system-site-packages virtualenvs, but they can be a good way to deal
    with this.

    Can you name any package using this mechanism so I can have a look?

    wheel uses tox tests, in about the most straightforward way possible
    (declare build-depends on tox).

    Sometimes you'll need to patch tox.ini to add things to
    allowlist_externals, because we're using --system-site-packages.

    You'll also need to Build-Depend on everything that tox wants to install
    into the virtualenv.

    Some more examples:

    $ reverse-depends -b tox
    Reverse-Build-Depends
    =====================
    * anosql
    * ceph
    * custodia
    * diskcache
    * django-auth-ldap
    * duplicity
    * enlighten
    * flask-jwt-simple
    * git-imerge
    * gitsome
    * gnome-keysign
    * gubbins
    * mitmproxy
    * pytest-datadir
    * pytest-mypy-plugins
    * python-django-solo
    * python-json-log-formatter
    * python-kdcproxy
    * python-magic
    * python-mrcfile
    * python-nox
    * python-pkginfo
    * python-prettylog
    * python-pyforge
    * python-pyvmomi
    * python-versioneer
    * python-w3lib
    * pytrainer
    * rdflib-sqlalchemy
    * reprotest
    * sagemath
    * sagenb-export
    * sshtunnel
    * tox-current-env
    * wheel

    Reverse-Build-Depends-Indep
    ===========================
    * awscli
    * python-bottle
    * python-scrapy


    I'm not really experienced with tox, so it would be great to have some guidance in the form of sample code.

    Adrian

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer
    `. `' Physicist
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913


    --
    Stefano Rivera
    http://tumbleweed.org.za/
    +1 415 683 3272

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)