Skip to contentSkip to conversation

python3-betamax: skip the live-network hook tests in ptest

PATCH New Khem Raj 1 participant 5 messages Sep 12

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/5 python3-betamax: skip the live-network hook tests in ptest

tests/integration/test_hooks.py records live https://httpbin.org
requests (no cassettes are shipped for them), so the ptest fails whenever the service resets the connection, e.g.:

FAIL: tests/integration/test_hooks.py:TestHooks.test_post_start_hook requests.exceptions.ConnectionError: ('Connection aborted.',
ConnectionResetError(104, 'Connection reset by peer'))

The same tests pass when the service behaves (3 out of 3 runs in a qemux86-64 VM), so they are flaky rather than broken. Leave them out of the ptest run.

AI-Generated: Uses Claude Code

---
 .../recipes-devtools/python/python3-betamax/run-ptest        | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
meta-python/recipes-devtools/python/python3-betamax/run-ptest +4 -1
index 531af4d015..0acad79f97 100644
@@ -8,4 +8,7 @@ if ! nslookup httpbin.org >/dev/null 2>&1 ; then
     echo "nameserver 8.8.8.8" > /etc/resolv.conf
 fi
 
-pytest --automake
+# tests/integration/test_hooks.py records live https://httpbin.org requests
+# (no cassettes are shipped for it) and fails whenever the service resets
+# the connection, so leave it out.
+pytest --automake --ignore=tests/integration/test_hooks.py
author
#1 lore raw

PATCH 2/5 python3-glances: install config and test data for ptest

tests/test_core.py runs glances with ./conf/glances.conf and reads plugin test data from ./tests-data, both relative to the ptest directory. Neither was installed, and tests-data is not part of the pypi sdist, so four tests failed:

test_023_get_alert: AssertionError: 'DEFAULT' != 'OK_LOG'
test_025_npu: IndexError: list index out of range
test_026_mpp: AssertionError: 0 != 3 : Expected 3 MPP engines
test_108_fs_zfs_: AssertionError: False is not true

Fetch tests-data from the v4.5.6 tag and install it, together with conf/, next to the tests. Only tests-data/plugins is used by the tests.

With these in place tests/test_core.py passes 52/52 on qemux86-64.

AI-Generated: Uses Claude Code

---
 .../recipes-devtools/python/python3-glances_4.5.6.bb | 12 ++++++++++++
 1 file changed, 12 insertions(+)
meta-python/recipes-devtools/python/python3-glances_4.5.6.bb +12 -0
index 41516e07bc..311d38cac3 100644
@@ -11,7 +11,19 @@ inherit pypi python_setuptools_build_meta ptest-python-pytest
 
 SRC_URI += " \
 	file://run-ptest \
+	git://github.com/nicolargo/glances.git;protocol=https;branch=master;name=testsdata;subpath=tests-data;destsuffix=glances-tests-data \
 "
+# tests-data/ is used by tests/test_core.py but not shipped in the pypi sdist,
+# take it from the v4.5.6 tag
+SRCREV_testsdata = "ce2f8506289c71e48ed8bf186f2c04d8256203d5"
+
+# tests/test_core.py runs glances with ./conf/glances.conf and reads plugin
+# test data from ./tests-data, both relative to the ptest directory
+do_install_ptest:append() {
+	install -d ${D}${PTEST_PATH}/conf ${D}${PTEST_PATH}/tests-data
+	cp -rf ${S}/conf/* ${D}${PTEST_PATH}/conf/
+	cp -rf ${UNPACKDIR}/glances-tests-data/plugins ${D}${PTEST_PATH}/tests-data/
+}
 
 # psutil/jinja2/packaging are oe-core; fastapi/uvicorn/defusedxml are
 # meta-python.
author
#2 lore raw

PATCH 3/5 python3-fastnumbers: fix denoise of large floats when built with clang

In reply to Khem Raj

float_as_int_without_noise() returns early when the floored value fits in a long, checking it with floor_val == static_cast<long>(floor_val). For values outside the range of long the conversion is undefined behavior; clang -O2 folds the round trip into "floor_val is integral", which is always true, so the denoising is skipped:

FAIL: tests/test_fastnumbers_examples.py:test_try_real
FAIL: tests/test_fastnumbers_examples.py:test_try_forceint assert 3452999999999999737856 == 3453000000000000000000

Add a patch that only does the conversion when the value is in range. A reduced reproducer returns the wrong answer with the recipe's clang++ at -O2 and the right one with the fix (and with -O0 or gcc).

AI-Generated: Uses Claude Code

---
 ...efined-double-to-long-conversion-in-.patch | 46 +++++++++++++++++++
 .../python/python3-fastnumbers_5.2.0.bb       |  1 +
 2 files changed, 47 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-fastnumbers/0001-parser-avoid-undefined-double-to-long-conversion-in-.patch
meta-python/recipes-devtools/python/python3-fastnumbers/0001-parser-avoid-undefined-double-to-long-conversion-in-.patch new file +46 -0
new file mode 100644
index 0000000000..52275c1d8e
@@ -0,0 +1,46 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sat, 12 Sep 2026 00:00:00 -0700
+Subject: [PATCH] parser: avoid undefined double to long conversion in
+ float_as_int_without_noise
+
+float_as_int_without_noise() returns early when the floored value fits
+in a long:
+
+    if (floor_val == static_cast<long>(floor_val))
+
+For values outside the range of long (e.g. 3.453e21) the conversion is
+undefined behavior. clang (-O2) takes advantage of that and folds the
+round trip into "floor_val is integral", which is always true, so the
+denoising is skipped and try_real(3.453e21, denoise=True) returns
+3452999999999999737856 instead of 3453000000000000000000:
+
+  tests/test_fastnumbers_examples.py::test_try_real FAILED
+  tests/test_fastnumbers_examples.py::test_try_forceint FAILED
+
+Only do the conversion when the value is within the range of long.
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <[email protected]>
+---
+ src/cpp/parser.cpp | 8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+--- a/src/cpp/parser.cpp
++++ b/src/cpp/parser.cpp
+@@ -92,8 +92,14 @@
+ 
+     // If the given float can fit a C long without loss then no need
+     // to go through the below rounding steps.
++    // Converting a double that is outside the range of long is undefined
++    // behavior, and clang uses that to fold this check into "floor_val is
++    // integral", which is always true and skips the denoising below for large
++    // values. Make sure the value is in range before converting.
+     const double floor_val = std::floor(val);
+-    if (floor_val == static_cast<long>(floor_val)) {
++    constexpr double long_limit = -static_cast<double>(std::numeric_limits<long>::min());
++    if (floor_val >= -long_limit && floor_val < long_limit
++        && floor_val == static_cast<long>(floor_val)) {
+         return val_int;
+     }
+ 
meta-python/recipes-devtools/python/python3-fastnumbers_5.2.0.bb +1 -0
index 65d7fcea3f..d067e44938 100644
@@ -4,6 +4,7 @@ LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=d32431d1b650010945da4e078011c8fa"
 
 
+SRC_URI += "file://0001-parser-avoid-undefined-double-to-long-conversion-in-.patch"
 SRC_URI[sha256sum] = "07266a2fca9e08eeb5a6c70be4c8db3637db9b930ea5198facbbb9b0b31d4d03"
 
 inherit pypi python_setuptools_build_meta ptest-python-pytest
author
#3 lore raw

PATCH 4/5 python3-dnspython: skip DDR tests when DDR is not available

In reply to Khem Raj

test_basic_ddr_sync and test_basic_ddr_async only check that the Internet is reachable. On networks that intercept port 53, 1.1.1.1 and 8.8.8.8 still answer ordinary queries but return NXDOMAIN for _dns.resolver.arpa SVCB, so try_ddr() cannot upgrade the nameservers and the tests fail:

FAIL: tests/test_ddr.py:test_basic_ddr_sync
FAIL: tests/test_ddr.py:test_basic_ddr_async assert isinstance('1.1.1.1', dns.nameserver.Nameserver)

Add a patch to skip them unless both resolvers return DDR SVCB records.

AI-Generated: Uses Claude Code

---
 ...ests-when-the-resolvers-do-not-answe.patch | 70 +++++++++++++++++++
 .../python/python3-dnspython_2.8.0.bb         |  1 +
 2 files changed, 71 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-dnspython/0001-tests-skip-DDR-tests-when-the-resolvers-do-not-answe.patch
meta-python/recipes-devtools/python/python3-dnspython/0001-tests-skip-DDR-tests-when-the-resolvers-do-not-answe.patch new file +70 -0
new file mode 100644
index 0000000000..991604682e
@@ -0,0 +1,70 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sat, 12 Sep 2026 00:00:00 -0700
+Subject: [PATCH] tests: skip DDR tests when the resolvers do not answer DDR
+
+test_basic_ddr_sync and test_basic_ddr_async only check that the
+Internet is reachable. On networks that intercept port 53 with a
+transparent DNS proxy, 1.1.1.1 and 8.8.8.8 still answer ordinary
+queries but return NXDOMAIN for _dns.resolver.arpa SVCB, so try_ddr()
+cannot upgrade the nameservers and the tests fail:
+
+  assert isinstance('1.1.1.1', dns.nameserver.Nameserver)
+
+Skip the tests unless both resolvers return DDR SVCB records.
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <[email protected]>
+---
+ tests/test_ddr.py | 27 +++++++++++++++++++++++++--
+ 1 file changed, 25 insertions(+), 2 deletions(-)
+
+--- a/tests/test_ddr.py
++++ b/tests/test_ddr.py
+@@ -6,13 +6,36 @@
+ 
+ import dns.asyncbackend
+ import dns.asyncresolver
++import dns.message
+ import dns.nameserver
++import dns.query
++import dns.rdatatype
+ import dns.resolver
+ import tests.util
+ 
+ 
++def _ddr_available():
++    """Check that the public resolvers answer the DDR SVCB query.
++
++    Networks that intercept port 53 (e.g. a transparent DNS proxy) answer
++    _dns.resolver.arpa with NXDOMAIN, so DDR cannot work there even though
++    the Internet is reachable.
++    """
++    if not tests.util.is_internet_reachable():
++        return False
++    for nameserver in ["1.1.1.1", "8.8.8.8"]:
++        q = dns.message.make_query("_dns.resolver.arpa", dns.rdatatype.SVCB)
++        try:
++            r = dns.query.udp(q, nameserver, timeout=5)
++        except Exception:
++            return False
++        if not r.answer:
++            return False
++    return True
++
++
+ @pytest.mark.skipif(
+-    not tests.util.is_internet_reachable(), reason="Internet not reachable"
++    not _ddr_available(), reason="Internet not reachable or DDR not available"
+ )
+ @tests.util.retry_on_timeout
+ def test_basic_ddr_sync():
+@@ -26,7 +49,7 @@
+ 
+ 
+ @pytest.mark.skipif(
+-    not tests.util.is_internet_reachable(), reason="Internet not reachable"
++    not _ddr_available(), reason="Internet not reachable or DDR not available"
+ )
+ @tests.util.retry_on_timeout
+ def test_basic_ddr_async():
meta-python/recipes-devtools/python/python3-dnspython_2.8.0.bb +1 -0
index aa14caed15..859b71bcda 100644
@@ -11,6 +11,7 @@ inherit pypi python_hatchling ptest
 
 SRC_URI += " \
 	file://run-ptest \
+	file://0001-tests-skip-DDR-tests-when-the-resolvers-do-not-answe.patch \
 "
 
 RDEPENDS:${PN}-ptest += " \
author
#4 lore raw

PATCH 5/5 python3-pylint: fix crash with astroid >= 4.2

In reply to Khem Raj

pylint 4.0.8 passes asname=False to Import.infer(), a keyword argument astroid 4.2 removed. With the astroid 4.3.1 in meta-python this makes pylint crash on any import of a missing submodule:

TypeError: NodeNG.infer() got an unexpected keyword argument 'asname'

which shows up in ptest as astroid-error in three functional tests:

FAIL: tests/test_functional.py:test_functional[fallback_import_enabled]
FAIL: tests/test_functional.py:test_functional[import_error]
FAIL: tests/test_functional.py:test_functional[no_name_in_module]

Backport the pylint/ part of upstream commit 554b1d192434 ("Bump astroid to 4.2.0b4"), which drops the argument.

meta-python-image-ptest-python3-pylint on qemux86-64 now passes 872 tests with none failing.

AI-Generated: Uses Claude Code

---
 ...s-do-not-pass-asname-to-Import.infer.patch | 39 +++++++++++++++++++
 .../python/python3-pylint_4.0.8.bb            |  1 +
 2 files changed, 40 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-pylint/0004-checkers-variables-do-not-pass-asname-to-Import.infer.patch
meta-python/recipes-devtools/python/python3-pylint/0004-checkers-variables-do-not-pass-asname-to-Import.infer.patch new file +39 -0
new file mode 100644
index 0000000000..411ba313fc
@@ -0,0 +1,39 @@
+From 554b1d1924342ce2e5b4d8f79dd62eab7cd67501 Mon Sep 17 00:00:00 2001
+From: Daniël van Noord <[email protected]>
+Date: Sat, 4 Jul 2026 23:17:33 +0200
+Subject: [PATCH] checkers/variables: do not pass asname to Import.infer()
+
+astroid 4.2 removed the asname keyword argument from Import/ImportFrom
+inference (astroid commit fe29fb1f7e3e, "Remove `asname` kwarg from
+Import/ImportFrom `_infer`"). With astroid >= 4.2, pylint 4.0.8 then
+crashes on any module that imports a missing submodule of a package:
+
+  TypeError: NodeNG.infer() got an unexpected keyword argument 'asname'
+  ... (astroid-error)
+
+which breaks the fallback_import_enabled, import_error and
+no_name_in_module functional tests with the astroid 4.3.1 in meta-python.
+
+This is the pylint/ part of upstream commit 554b1d192434
+("Bump `astroid` to `4.2.0b4` (#11153)"); the astroid version pin
+changes in pyproject.toml and requirements_test_min.txt are left out.
+
+Upstream-Status: Backport [https://github.com/pylint-dev/pylint/commit/554b1d192434]
+Signed-off-by: Khem Raj <[email protected]>
+---
+ pylint/checkers/variables.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
+index 3ce7dc63410..7e5f27b70ef 100644
+--- a/pylint/checkers/variables.py
++++ b/pylint/checkers/variables.py
+@@ -217,7 +217,7 @@ class C: ...
+ def _infer_name_module(node: nodes.Import, name: str) -> Generator[InferenceResult]:
+     context = astroid.context.InferenceContext()
+     context.lookupname = name
+-    return node.infer(context, asname=False)  # type: ignore[no-any-return]
++    return node.infer(context)  # type: ignore[no-any-return]
+ 
+ 
+ def _fix_dot_imports(
meta-python/recipes-devtools/python/python3-pylint_4.0.8.bb +1 -0
index 90ee93e4f9..9ae03295e7 100644
@@ -8,6 +8,7 @@ SRC_URI += "git://github.com/pylint-dev/pylint;branch=main;protocol=https;tag=v$
            file://0001-Adjust-test-expectations-for-ptest.patch \
            file://0002-pyproject.toml-Keep-tool.setuptools.license-files.patch \
            file://0003-astroid-4.1.2-endlineno.patch \
+           file://0004-checkers-variables-do-not-pass-asname-to-Import.infer.patch \
            file://run-ptest \
            "