• [gentoo-dev] [PATCH 0/4] python-utils-r1.eclass: hypothesis-gentoo supp

    From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Tue Jul 8 08:10:01 2025
    Hello,

    Here's another patchset for epytest:

    1. Add support for using '--hypothesis-profile=gentoo' when
    hypothesis-gentoo is installed (to be added along with the patchset).
    This profile disables all health checks, i.e. lints that fail
    randomly depending on system load.

    2. Fix EPYTEST_PLUGINS (the downstream variable) not to add '-p' options
    when the same plugin is already loaded via PYTEST_PLUGINS
    (the upstream variable), as otherwise it ends up being loaded twice
    and things explode.

    3. Add EPYTEST_PLUGIN_LOAD_VIA_ENV to switch from using '-p' options
    (recommended in general) to using PYTEST_PLUGINS (needed mostly
    for testing pytest plugins themselves).



    Michał Górny (4):
    python-utils-r1.eclass: epytest, support --hypothesis-profile=gentoo
    python-utils-r1.eclass: epytest, avoid dupes w/ PYTEST_PLUGINS
    python-utils-r1.eclass: Add EPYTEST_PLUGIN_LOAD_VIA_ENV
    dev-python/pytest-regressions: Use EPYTEST_PLUGIN_LOAD_VIA_ENV

    .../pytest-regressions-2.8.1.ebuild | 3 +-
    eclass/python-utils-r1.eclass | 70 +++++++++++++++----
    2 files changed, 58 insertions(+), 15 deletions(-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Tue Jul 8 08:20:01 2025
    Add an `EPYTEST_PLUGIN_LOAD_VIA_ENV` option to explicitly load plugins
    via `PYTEST_PLUGINS` environment variable rather than `-p` options.
    This is useful for testing pytest plugins.

    While the use case is not very common and therefore may not deserve
    explicit eclass support, the value of `PYTEST_PLUGINS` consists
    of Python import names that are not trivial to find and have
    historically changed across package versions.

    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    ---
    eclass/python-utils-r1.eclass | 62 +++++++++++++++++++++++++----------
    1 file changed, 45 insertions(+), 17 deletions(-)

    diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index bbb57901f281..68faa9e2adf9 100644
    --- a/eclass/python-utils-r1.eclass
    +++ b/eclass/python-utils-r1.eclass
    @@ -1312,6 +1312,15 @@ _python_check_occluded_packages() {
    # The recommended way to disable it in EAPI 8 or earlier is to set
    # EPYTEST_PLUGINS (possibly to an empty array).

    +# @ECLASS_VARIABLE: EPYTEST_PLUGIN_LOAD_VIA_ENV
    +# @DEFAULT_UNSET
    +# @DESCRIPTION:
    +# If set to a non-empty value, plugins will be loaded via PYTEST_PLUGINS
    +# environment variable rather than explicit "-p" options. This ensures
    +# that plugins are passed down to subprocess, which may be necessary
    +# when testing pytest plugins. However, this is also more likely
    +# to cause duplicate plugin errors.
    +
    # @FUNCTION: _set_epytest_plugins
    # @INTERNAL
    # @DESCRIPTION:
    @@ -1442,23 +1451,39 @@ epytest() {
  • From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Tue Jul 8 08:20:01 2025
    Avoid adding duplicate `-p` arguments when the plugin in question
    is already loaded via `PYTEST_PLUGINS`. This avoids errors when
    combining dependency adding via `EPYTEST_PLUGINS` with explicit loading
    via `PYTEST_PLUGINS` (as needed for plugin tests themselves).

    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    ---
    eclass/python-utils-r1.eclass | 5 ++++-
    1 file changed, 4 insertions(+), 1 deletion(-)

    diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index 9e94acf34edf..bbb57901f281 100644
    --- a/eclass/python-utils-r1.eclass
    +++ b/eclass/python-utils-r1.eclass
    @@ -1445,12 +1445,15 @@ epytest() {
    local plugin_args=()
    readarray -t -d '' plugin_args < <(
    "${EPYTHON}" - "${EPYTEST_PLUGINS[@]}" <<-EOF || die
    + import os
    import sys
    from importlib.metadata import distribution, entry_points
    +
    + env_plugins = os.environ.get("PYTEST_PLUGINS", "").split(",")
    packages = {distribution(x).name for x in sys.argv[1:]}
    eps = {
    f"-p{x.name}" for x in entry_points(group="pytest11")
    - if x.dist.name in packages
    + if x.dist.name in packages and x.value not in env_plugins
    }
    sys.stdout.write("\\0".join(sorted(eps)))
    EOF

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Tue Jul 8 08:20:01 2025
    Support using the "gentoo" hypothesis profile, as installed
    by dev-python/hypothesis-gentoo, to disable all Hypothesis health
    checks. This avoids spurious test failures, e.g. when the system is
    under load and the strategies are underperforming.

    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    ---
    eclass/python-utils-r1.eclass | 11 +++++++++++
    1 file changed, 11 insertions(+)

    diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index dce565b8b036..9e94acf34edf 100644
    --- a/eclass/python-utils-r1.eclass
    +++ b/eclass/python-utils-r1.eclass
    @@ -1518,6 +1518,17 @@ epytest() {
    fi
    fi

    + # If we are using hypothesis (require use via EPYTEST_PLUGINS, since
    + # ebuilds may disable autoloading manually) *and* hypothesis-gentoo
    + # is available, use it to disable all health checks, to prevent the tests
    + # from failing randomly under load.
    + if has hypothesis "${EPYTEST_PLUGINS[@]}" &&
    + "${EPYTHON}" -c 'import hypothesis_gentoo' 2>/dev/null &&
    + [[ ! ${HYPOTHESIS_NO_PLUGINS} ]]
    + then
    + args+=( --hypothesis-profile=gentoo )
    + fi
    +
    local x
    for x in "${EPYTEST_DESELECT[@]}"; do
    args+=( --deselect "${x}" )

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