summaryrefslogtreecommitdiffstats
path: root/meta-python
diff options
context:
space:
mode:
authorGyorgy Sarvari <skandigraun@gmail.com>2025-10-19 17:59:26 +0200
committerGyorgy Sarvari <skandigraun@gmail.com>2025-10-20 11:59:36 +0200
commitb476f98381af7e7b369e788fffee817d4e4ebb45 (patch)
tree1c61af4d1993adf6c1affa3abdd946c93542806f /meta-python
parent975abfa25971b08d2296db65ddeeea87d566de53 (diff)
downloadmeta-openembedded-b476f98381af7e7b369e788fffee817d4e4ebb45.tar.gz
python3-betamax: fix ptests
1. Some tests require internet access. Set a DNS for that, if it is not available at the start of the test. 2. Added a backported patch that fixes some failing tests, due to a variable header value contained in a response. (fix-failing-ptest.patch) 3. Added a backported patch that avoids calling pytest fixtures directly. If not applied, tests calling them are marked as failing by pytest. (fix-direct-calls-to-test-fixtures.patch) Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
Diffstat (limited to 'meta-python')
-rw-r--r--meta-python/recipes-devtools/python/python3-betamax/fix-direct-calls-to-test-fixtures.patch41
-rw-r--r--meta-python/recipes-devtools/python/python3-betamax/fix-failing-ptest.patch44
-rw-r--r--meta-python/recipes-devtools/python/python3-betamax/run-ptest6
-rw-r--r--meta-python/recipes-devtools/python/python3-betamax_0.8.1.bb2
4 files changed, 93 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-betamax/fix-direct-calls-to-test-fixtures.patch b/meta-python/recipes-devtools/python/python3-betamax/fix-direct-calls-to-test-fixtures.patch
new file mode 100644
index 0000000000..284506867a
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-betamax/fix-direct-calls-to-test-fixtures.patch
@@ -0,0 +1,41 @@
1From 165cc321f2b9839418269e9493b03eb2e43f7ddf Mon Sep 17 00:00:00 2001
2From: Jiri Kuncar <jiri.kuncar@gmail.com>
3Date: Mon, 9 Sep 2019 12:23:18 +0200
4Subject: [PATCH] tests: fix direct calls to PyTest fixtures
5
6https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly
7
8Upstream-Status: Backport [https://github.com/betamaxpy/betamax/commit/165cc321f2b9839418269e9493b03eb2e43f7ddf]
9Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
10---
11 tests/unit/test_fixtures.py | 8 ++++----
12 1 file changed, 4 insertions(+), 4 deletions(-)
13
14diff --git a/tests/unit/test_fixtures.py b/tests/unit/test_fixtures.py
15index 387d9ce..41f33eb 100644
16--- a/tests/unit/test_fixtures.py
17+++ b/tests/unit/test_fixtures.py
18@@ -27,9 +27,9 @@ def test_adds_stop_as_a_finalizer(self):
19 # Mock a pytest request object
20 request = mock.MagicMock()
21 request.cls = request.module = None
22- request.function.__name__ = 'test'
23+ request.node.name = request.function.__name__ = 'test'
24
25- pytest_fixture.betamax_recorder(request)
26+ pytest_fixture._betamax_recorder(request)
27 assert request.addfinalizer.called is True
28 request.addfinalizer.assert_called_once_with(self.mocked_betamax.stop)
29
30@@ -37,9 +37,9 @@ def test_auto_starts_the_recorder(self):
31 # Mock a pytest request object
32 request = mock.MagicMock()
33 request.cls = request.module = None
34- request.function.__name__ = 'test'
35+ request.node.name = request.function.__name__ = 'test'
36
37- pytest_fixture.betamax_recorder(request)
38+ pytest_fixture._betamax_recorder(request)
39 self.mocked_betamax.start.assert_called_once_with()
40
41
diff --git a/meta-python/recipes-devtools/python/python3-betamax/fix-failing-ptest.patch b/meta-python/recipes-devtools/python/python3-betamax/fix-failing-ptest.patch
new file mode 100644
index 0000000000..5671033526
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-betamax/fix-failing-ptest.patch
@@ -0,0 +1,44 @@
1From 0f5d51b1c7e3b9eb5c083621a00811a872323046 Mon Sep 17 00:00:00 2001
2From: Jaremy Hatler <hatler.jaremy@gmail.com>
3Date: Fri, 22 Dec 2023 22:53:53 -0500
4Subject: [PATCH] fix: clear X-Amzn-Trace-Id in httbin.org responses (#2)
5
6The httbin.org service returns a X-Amzn-Trace-Id header in its
7responses, which is different for each request. This causes the
8tests to fail. This clears the header before comparing responses.
9
10Refs: #184, #190
11Signed-off-by: Jaremy Hatler <hatler.jaremy@gmail.com>
12
13Upstream-Status: Backport [https://github.com/jhatler/betamax/commit/0f5d51b1c7e3b9eb5c083621a00811a872323046]
14---
15 tests/integration/test_record_modes.py | 11 ++++++++++-
16 1 file changed, 10 insertions(+), 1 deletion(-)
17
18diff --git a/tests/integration/test_record_modes.py b/tests/integration/test_record_modes.py
19index 58c8846..988b851 100644
20--- a/tests/integration/test_record_modes.py
21+++ b/tests/integration/test_record_modes.py
22@@ -1,3 +1,5 @@
23+import re
24+
25 from betamax import Betamax, BetamaxError
26
27 from tests.integration.helper import IntegrationHelper
28@@ -39,8 +41,15 @@ def test_replays_response_from_cassette(self):
29 # this test to succeed.
30 # NOTE(hroncok): httpbin.org added X-Processed-Time header that
31 # can possibly differ (and often does)
32+ r0_content = r0.content.decode(encoding='utf-8', errors='strict')
33+ r1_content = r1.content.decode(encoding='utf-8', errors='strict')
34+ r0_content = re.sub('"X-Amzn-Trace-Id": "[^"]+"', '"X-Amzn-Trace-Id": ""', r0_content)
35+ r1_content = re.sub('"X-Amzn-Trace-Id": "[^"]+"', '"X-Amzn-Trace-Id": ""', r1_content)
36+ # NOTE(jhatler): httpbin.org added "X-Amzn-Trace-Id" to their
37+ # response, which is a unique ID that will differ between requests.
38+ # We remove it from the response body before comparing.
39 assert r0_headers == r1_headers
40- assert r0.content == r1.content
41+ assert r0_content == r1_content
42
43
44 class TestRecordNone(IntegrationHelper):
diff --git a/meta-python/recipes-devtools/python/python3-betamax/run-ptest b/meta-python/recipes-devtools/python/python3-betamax/run-ptest
index b63c4de0d9..7553a6d4bc 100644
--- a/meta-python/recipes-devtools/python/python3-betamax/run-ptest
+++ b/meta-python/recipes-devtools/python/python3-betamax/run-ptest
@@ -1,3 +1,9 @@
1#!/bin/sh 1#!/bin/sh
2 2
3if ! nslookup httpbin.org >/dev/null 2>&1 ; then
4 trap 'mv /etc/resolv.conf.bak /etc/resolv.conf' INT EXIT
5 mv /etc/resolv.conf /etc/resolv.conf.bak
6 echo "nameserver 8.8.8.8" > /etc/resolv.conf
7fi
8
3pytest -o log_cli=true -o log_cli_level=INFO | sed -e 's/\[...%\]//g'| sed -e 's/PASSED/PASS/g'| sed -e 's/FAILED/FAIL/g'|sed -e 's/SKIPPED/SKIP/g'| awk '{if ($NF=="PASS" || $NF=="FAIL" || $NF=="SKIP" || $NF=="XFAIL" || $NF=="XPASS"){printf "%s: %s\n", $NF, $0}else{print}}'| awk '{if ($NF=="PASS" || $NF=="FAIL" || $NF=="SKIP" || $NF=="XFAIL" || $NF=="XPASS") {$NF="";print $0}else{print}}' 9pytest -o log_cli=true -o log_cli_level=INFO | sed -e 's/\[...%\]//g'| sed -e 's/PASSED/PASS/g'| sed -e 's/FAILED/FAIL/g'|sed -e 's/SKIPPED/SKIP/g'| awk '{if ($NF=="PASS" || $NF=="FAIL" || $NF=="SKIP" || $NF=="XFAIL" || $NF=="XPASS"){printf "%s: %s\n", $NF, $0}else{print}}'| awk '{if ($NF=="PASS" || $NF=="FAIL" || $NF=="SKIP" || $NF=="XFAIL" || $NF=="XPASS") {$NF="";print $0}else{print}}'
diff --git a/meta-python/recipes-devtools/python/python3-betamax_0.8.1.bb b/meta-python/recipes-devtools/python/python3-betamax_0.8.1.bb
index 2caeb5afa2..2d5b00e595 100644
--- a/meta-python/recipes-devtools/python/python3-betamax_0.8.1.bb
+++ b/meta-python/recipes-devtools/python/python3-betamax_0.8.1.bb
@@ -5,6 +5,8 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=61c15f0c146c5fb1a8ce8ba2f310d73c"
5 5
6SRC_URI += " \ 6SRC_URI += " \
7 file://run-ptest \ 7 file://run-ptest \
8 file://fix-failing-ptest.patch \
9 file://fix-direct-calls-to-test-fixtures.patch \
8" 10"
9 11
10SRC_URI[md5sum] = "b8182d43a200fc126a3bf7555626f964" 12SRC_URI[md5sum] = "b8182d43a200fc126a3bf7555626f964"