diff options
| author | Zhixiong Chi <zhixiong.chi@windriver.com> | 2023-03-28 03:20:07 -0700 |
|---|---|---|
| committer | Khem Raj <raj.khem@gmail.com> | 2023-03-28 10:44:00 -0700 |
| commit | 17243e70c8309751a1129a9214899ec476ab121a (patch) | |
| tree | 717c8d01a7f28ff84f7a1a20799b043d5d85839b /meta-python | |
| parent | 6b12086873a5e0707c6e35d55967c8c8183c6adb (diff) | |
| download | meta-openembedded-17243e70c8309751a1129a9214899ec476ab121a.tar.gz | |
python3-betamax: fix ptest failture of fixture and record modes
In betamax fixtures and recorde_modes ptest are failing due to
the deprecation of fixture usage and the httpbin.org service.
Drop these ptests in meta-oe, until there is a suitable solution
to fix this failure.
Validation:
Enable ptest and add python3-betamax into IMAGE_INSTALL
$runqemu ...
$cd /usr/[lib/lib64]/python3-betamax/ptest
$./run-ptest
ALL ptests PASS.
Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Diffstat (limited to 'meta-python')
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-betamax/0001-Drop-ptests-fixtures-and-recorde_modes.patch | 333 | ||||
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-betamax_0.8.1.bb | 1 |
2 files changed, 334 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-betamax/0001-Drop-ptests-fixtures-and-recorde_modes.patch b/meta-python/recipes-devtools/python/python3-betamax/0001-Drop-ptests-fixtures-and-recorde_modes.patch new file mode 100644 index 0000000000..7adcb68324 --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-betamax/0001-Drop-ptests-fixtures-and-recorde_modes.patch | |||
| @@ -0,0 +1,333 @@ | |||
| 1 | From 0e0b63ae80df5d7849b2e1c5ab9a668e8378b5e8 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Zhixiong Chi <zhixiong.chi@windriver.com> | ||
| 3 | Date: Tue, 28 Mar 2023 06:05:45 +0000 | ||
| 4 | Subject: [PATCH] Drop ptests fixtures and recorde_modes | ||
| 5 | |||
| 6 | The usage of fixture in test_fixtures has been deprecated. | ||
| 7 | See https://docs.pytest.org/en/stable/explanation/fixtures.html and | ||
| 8 | https://docs.pytest.org/en/stable/deprecations.html#calling-fixtures-directly | ||
| 9 | for more information about fixtures. | ||
| 10 | Meanwhile the test_record_modes relies on httpbin.org which has been sold and | ||
| 11 | re-sold several times, and it adds X-Amzn-Trace-Id header that can possibly | ||
| 12 | diff for each request. | ||
| 13 | It leads to ptest failure, so drop it now until we find the solution. | ||
| 14 | |||
| 15 | Upstream-Status: Inappropriate [oe specific] | ||
| 16 | |||
| 17 | Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com> | ||
| 18 | --- | ||
| 19 | tests/integration/test_fixtures.py | 60 ----------- | ||
| 20 | tests/integration/test_record_modes.py | 132 ------------------------- | ||
| 21 | tests/unit/test_fixtures.py | 94 ------------------ | ||
| 22 | 3 files changed, 286 deletions(-) | ||
| 23 | delete mode 100644 tests/integration/test_fixtures.py | ||
| 24 | delete mode 100644 tests/integration/test_record_modes.py | ||
| 25 | delete mode 100644 tests/unit/test_fixtures.py | ||
| 26 | |||
| 27 | diff --git a/tests/integration/test_fixtures.py b/tests/integration/test_fixtures.py | ||
| 28 | deleted file mode 100644 | ||
| 29 | index fc3d1e7..0000000 | ||
| 30 | --- a/tests/integration/test_fixtures.py | ||
| 31 | +++ /dev/null | ||
| 32 | @@ -1,60 +0,0 @@ | ||
| 33 | -import os.path | ||
| 34 | - | ||
| 35 | -import pytest | ||
| 36 | - | ||
| 37 | - | ||
| 38 | -@pytest.mark.usefixtures('betamax_session') | ||
| 39 | -class TestPyTestFixtures: | ||
| 40 | - @pytest.fixture(autouse=True) | ||
| 41 | - def setup(self, request): | ||
| 42 | - """After test hook to assert everything.""" | ||
| 43 | - def finalizer(): | ||
| 44 | - test_dir = os.path.abspath('.') | ||
| 45 | - cassette_name = ('tests.integration.test_fixtures.' # Module name | ||
| 46 | - 'TestPyTestFixtures.' # Class name | ||
| 47 | - 'test_pytest_fixture' # Test function name | ||
| 48 | - '.json') | ||
| 49 | - file_name = os.path.join(test_dir, 'tests', 'cassettes', | ||
| 50 | - cassette_name) | ||
| 51 | - assert os.path.exists(file_name) is True | ||
| 52 | - | ||
| 53 | - request.addfinalizer(finalizer) | ||
| 54 | - | ||
| 55 | - def test_pytest_fixture(self, betamax_session): | ||
| 56 | - """Exercise the fixture itself.""" | ||
| 57 | - resp = betamax_session.get('https://httpbin.org/get') | ||
| 58 | - assert resp.ok | ||
| 59 | - | ||
| 60 | - | ||
| 61 | -@pytest.mark.usefixtures('betamax_parametrized_session') | ||
| 62 | -class TestPyTestParametrizedFixtures: | ||
| 63 | - @pytest.fixture(autouse=True) | ||
| 64 | - def setup(self, request): | ||
| 65 | - """After test hook to assert everything.""" | ||
| 66 | - def finalizer(): | ||
| 67 | - test_dir = os.path.abspath('.') | ||
| 68 | - cassette_name = ('tests.integration.test_fixtures.' # Module name | ||
| 69 | - 'TestPyTestParametrizedFixtures.' # Class name | ||
| 70 | - 'test_pytest_fixture' # Test function name | ||
| 71 | - '[https---httpbin.org-get]' # Parameter | ||
| 72 | - '.json') | ||
| 73 | - file_name = os.path.join(test_dir, 'tests', 'cassettes', | ||
| 74 | - cassette_name) | ||
| 75 | - assert os.path.exists(file_name) is True | ||
| 76 | - | ||
| 77 | - request.addfinalizer(finalizer) | ||
| 78 | - | ||
| 79 | - @pytest.mark.parametrize('url', ('https://httpbin.org/get',)) | ||
| 80 | - def test_pytest_fixture(self, betamax_parametrized_session, url): | ||
| 81 | - """Exercise the fixture itself.""" | ||
| 82 | - resp = betamax_parametrized_session.get(url) | ||
| 83 | - assert resp.ok | ||
| 84 | - | ||
| 85 | - | ||
| 86 | -@pytest.mark.parametrize('problematic_arg', [r'aaa\bbb', 'ccc:ddd', 'eee*fff']) | ||
| 87 | -def test_pytest_parametrize_with_filesystem_problematic_chars( | ||
| 88 | - betamax_parametrized_session, problematic_arg): | ||
| 89 | - """ | ||
| 90 | - Exercice parametrized args containing characters which might cause | ||
| 91 | - problems when getting translated into file names. """ | ||
| 92 | - assert True | ||
| 93 | diff --git a/tests/integration/test_record_modes.py b/tests/integration/test_record_modes.py | ||
| 94 | deleted file mode 100644 | ||
| 95 | index 58c8846..0000000 | ||
| 96 | --- a/tests/integration/test_record_modes.py | ||
| 97 | +++ /dev/null | ||
| 98 | @@ -1,132 +0,0 @@ | ||
| 99 | -from betamax import Betamax, BetamaxError | ||
| 100 | - | ||
| 101 | -from tests.integration.helper import IntegrationHelper | ||
| 102 | - | ||
| 103 | - | ||
| 104 | -class TestRecordOnce(IntegrationHelper): | ||
| 105 | - def test_records_new_interaction(self): | ||
| 106 | - s = self.session | ||
| 107 | - with Betamax(s).use_cassette('test_record_once') as betamax: | ||
| 108 | - self.cassette_path = betamax.current_cassette.cassette_path | ||
| 109 | - assert betamax.current_cassette.is_empty() is True | ||
| 110 | - r = s.get('http://httpbin.org/get') | ||
| 111 | - assert r.status_code == 200 | ||
| 112 | - assert betamax.current_cassette.is_empty() is True | ||
| 113 | - assert betamax.current_cassette.interactions != [] | ||
| 114 | - | ||
| 115 | - def test_replays_response_from_cassette(self): | ||
| 116 | - s = self.session | ||
| 117 | - with Betamax(s).use_cassette('test_replays_response') as betamax: | ||
| 118 | - self.cassette_path = betamax.current_cassette.cassette_path | ||
| 119 | - assert betamax.current_cassette.is_empty() is True | ||
| 120 | - r0 = s.get('http://httpbin.org/get') | ||
| 121 | - assert r0.status_code == 200 | ||
| 122 | - assert betamax.current_cassette.interactions != [] | ||
| 123 | - assert len(betamax.current_cassette.interactions) == 1 | ||
| 124 | - r1 = s.get('http://httpbin.org/get') | ||
| 125 | - assert len(betamax.current_cassette.interactions) == 2 | ||
| 126 | - assert r1.status_code == 200 | ||
| 127 | - r0_headers = r0.headers.copy() | ||
| 128 | - r0_headers.pop('Date') | ||
| 129 | - r0_headers.pop('Age', None) | ||
| 130 | - r0_headers.pop('X-Processed-Time', None) | ||
| 131 | - r1_headers = r1.headers.copy() | ||
| 132 | - r1_headers.pop('Date') | ||
| 133 | - r1_headers.pop('Age', None) | ||
| 134 | - r1_headers.pop('X-Processed-Time', None) | ||
| 135 | - # NOTE(sigmavirus24): This fails if the second request is | ||
| 136 | - # technically a second later. Ignoring the Date headers allows | ||
| 137 | - # this test to succeed. | ||
| 138 | - # NOTE(hroncok): httpbin.org added X-Processed-Time header that | ||
| 139 | - # can possibly differ (and often does) | ||
| 140 | - assert r0_headers == r1_headers | ||
| 141 | - assert r0.content == r1.content | ||
| 142 | - | ||
| 143 | - | ||
| 144 | -class TestRecordNone(IntegrationHelper): | ||
| 145 | - def test_raises_exception_when_no_interactions_present(self): | ||
| 146 | - s = self.session | ||
| 147 | - with Betamax(s) as betamax: | ||
| 148 | - betamax.use_cassette('test', record='none') | ||
| 149 | - self.cassette_created = False | ||
| 150 | - assert betamax.current_cassette is not None | ||
| 151 | - self.assertRaises(BetamaxError, s.get, 'http://httpbin.org/get') | ||
| 152 | - | ||
| 153 | - def test_record_none_does_not_create_cassettes(self): | ||
| 154 | - s = self.session | ||
| 155 | - with Betamax(s) as betamax: | ||
| 156 | - self.assertRaises(ValueError, betamax.use_cassette, | ||
| 157 | - 'test_record_none', record='none') | ||
| 158 | - self.cassette_created = False | ||
| 159 | - | ||
| 160 | - | ||
| 161 | -class TestRecordNewEpisodes(IntegrationHelper): | ||
| 162 | - def setUp(self): | ||
| 163 | - super(TestRecordNewEpisodes, self).setUp() | ||
| 164 | - with Betamax(self.session).use_cassette('test_record_new'): | ||
| 165 | - self.session.get('http://httpbin.org/get') | ||
| 166 | - self.session.get('http://httpbin.org/redirect/2') | ||
| 167 | - | ||
| 168 | - def test_records_new_events_with_existing_cassette(self): | ||
| 169 | - s = self.session | ||
| 170 | - opts = {'record': 'new_episodes'} | ||
| 171 | - with Betamax(s).use_cassette('test_record_new', **opts) as betamax: | ||
| 172 | - cassette = betamax.current_cassette | ||
| 173 | - self.cassette_path = cassette.cassette_path | ||
| 174 | - assert cassette.interactions != [] | ||
| 175 | - assert len(cassette.interactions) == 4 | ||
| 176 | - assert cassette.is_empty() is False | ||
| 177 | - s.get('https://httpbin.org/get') | ||
| 178 | - assert len(cassette.interactions) == 5 | ||
| 179 | - | ||
| 180 | - with Betamax(s).use_cassette('test_record_new') as betamax: | ||
| 181 | - cassette = betamax.current_cassette | ||
| 182 | - assert len(cassette.interactions) == 5 | ||
| 183 | - r = s.get('https://httpbin.org/get') | ||
| 184 | - assert r.status_code == 200 | ||
| 185 | - | ||
| 186 | - | ||
| 187 | -class TestRecordNewEpisodesCreatesCassettes(IntegrationHelper): | ||
| 188 | - def test_creates_new_cassettes(self): | ||
| 189 | - recorder = Betamax(self.session) | ||
| 190 | - opts = {'record': 'new_episodes'} | ||
| 191 | - cassette_name = 'test_record_new_makes_new_cassettes' | ||
| 192 | - with recorder.use_cassette(cassette_name, **opts) as betamax: | ||
| 193 | - self.cassette_path = betamax.current_cassette.cassette_path | ||
| 194 | - self.session.get('https://httpbin.org/get') | ||
| 195 | - | ||
| 196 | - | ||
| 197 | -class TestRecordAll(IntegrationHelper): | ||
| 198 | - def setUp(self): | ||
| 199 | - super(TestRecordAll, self).setUp() | ||
| 200 | - with Betamax(self.session).use_cassette('test_record_all'): | ||
| 201 | - self.session.get('http://httpbin.org/get') | ||
| 202 | - self.session.get('http://httpbin.org/redirect/2') | ||
| 203 | - self.session.get('http://httpbin.org/get') | ||
| 204 | - | ||
| 205 | - def test_records_new_interactions(self): | ||
| 206 | - s = self.session | ||
| 207 | - opts = {'record': 'all'} | ||
| 208 | - with Betamax(s).use_cassette('test_record_all', **opts) as betamax: | ||
| 209 | - cassette = betamax.current_cassette | ||
| 210 | - self.cassette_path = cassette.cassette_path | ||
| 211 | - assert cassette.interactions != [] | ||
| 212 | - assert len(cassette.interactions) == 5 | ||
| 213 | - assert cassette.is_empty() is False | ||
| 214 | - s.post('http://httpbin.org/post', data={'foo': 'bar'}) | ||
| 215 | - assert len(cassette.interactions) == 6 | ||
| 216 | - | ||
| 217 | - with Betamax(s).use_cassette('test_record_all') as betamax: | ||
| 218 | - assert len(betamax.current_cassette.interactions) == 6 | ||
| 219 | - | ||
| 220 | - def test_replaces_old_interactions(self): | ||
| 221 | - s = self.session | ||
| 222 | - opts = {'record': 'all'} | ||
| 223 | - with Betamax(s).use_cassette('test_record_all', **opts) as betamax: | ||
| 224 | - cassette = betamax.current_cassette | ||
| 225 | - self.cassette_path = cassette.cassette_path | ||
| 226 | - assert cassette.interactions != [] | ||
| 227 | - assert len(cassette.interactions) == 5 | ||
| 228 | - assert cassette.is_empty() is False | ||
| 229 | - s.get('http://httpbin.org/get') | ||
| 230 | - assert len(cassette.interactions) == 5 | ||
| 231 | diff --git a/tests/unit/test_fixtures.py b/tests/unit/test_fixtures.py | ||
| 232 | deleted file mode 100644 | ||
| 233 | index 387d9ce..0000000 | ||
| 234 | --- a/tests/unit/test_fixtures.py | ||
| 235 | +++ /dev/null | ||
| 236 | @@ -1,94 +0,0 @@ | ||
| 237 | -try: | ||
| 238 | - import unittest.mock as mock | ||
| 239 | -except ImportError: | ||
| 240 | - import mock | ||
| 241 | - | ||
| 242 | -import pytest | ||
| 243 | -import unittest | ||
| 244 | - | ||
| 245 | -import requests | ||
| 246 | - | ||
| 247 | -import betamax | ||
| 248 | -from betamax.fixtures import pytest as pytest_fixture | ||
| 249 | -from betamax.fixtures import unittest as unittest_fixture | ||
| 250 | - | ||
| 251 | - | ||
| 252 | -class TestPyTestFixture(unittest.TestCase): | ||
| 253 | - def setUp(self): | ||
| 254 | - self.mocked_betamax = mock.MagicMock() | ||
| 255 | - self.patched_betamax = mock.patch.object( | ||
| 256 | - betamax.recorder, 'Betamax', return_value=self.mocked_betamax) | ||
| 257 | - self.patched_betamax.start() | ||
| 258 | - | ||
| 259 | - def tearDown(self): | ||
| 260 | - self.patched_betamax.stop() | ||
| 261 | - | ||
| 262 | - def test_adds_stop_as_a_finalizer(self): | ||
| 263 | - # Mock a pytest request object | ||
| 264 | - request = mock.MagicMock() | ||
| 265 | - request.cls = request.module = None | ||
| 266 | - request.function.__name__ = 'test' | ||
| 267 | - | ||
| 268 | - pytest_fixture.betamax_recorder(request) | ||
| 269 | - assert request.addfinalizer.called is True | ||
| 270 | - request.addfinalizer.assert_called_once_with(self.mocked_betamax.stop) | ||
| 271 | - | ||
| 272 | - def test_auto_starts_the_recorder(self): | ||
| 273 | - # Mock a pytest request object | ||
| 274 | - request = mock.MagicMock() | ||
| 275 | - request.cls = request.module = None | ||
| 276 | - request.function.__name__ = 'test' | ||
| 277 | - | ||
| 278 | - pytest_fixture.betamax_recorder(request) | ||
| 279 | - self.mocked_betamax.start.assert_called_once_with() | ||
| 280 | - | ||
| 281 | - | ||
| 282 | -class FakeBetamaxTestCase(unittest_fixture.BetamaxTestCase): | ||
| 283 | - def test_fake(self): | ||
| 284 | - pass | ||
| 285 | - | ||
| 286 | - | ||
| 287 | -class TestUnittestFixture(unittest.TestCase): | ||
| 288 | - def setUp(self): | ||
| 289 | - self.mocked_betamax = mock.MagicMock() | ||
| 290 | - self.patched_betamax = mock.patch.object( | ||
| 291 | - betamax.recorder, 'Betamax', return_value=self.mocked_betamax) | ||
| 292 | - self.betamax = self.patched_betamax.start() | ||
| 293 | - self.fixture = FakeBetamaxTestCase(methodName='test_fake') | ||
| 294 | - | ||
| 295 | - def tearDown(self): | ||
| 296 | - self.patched_betamax.stop() | ||
| 297 | - | ||
| 298 | - def test_setUp(self): | ||
| 299 | - self.fixture.setUp() | ||
| 300 | - | ||
| 301 | - self.mocked_betamax.use_cassette.assert_called_once_with( | ||
| 302 | - 'FakeBetamaxTestCase.test_fake' | ||
| 303 | - ) | ||
| 304 | - self.mocked_betamax.start.assert_called_once_with() | ||
| 305 | - | ||
| 306 | - def test_setUp_rejects_arbitrary_session_classes(self): | ||
| 307 | - self.fixture.SESSION_CLASS = object | ||
| 308 | - | ||
| 309 | - with pytest.raises(AssertionError): | ||
| 310 | - self.fixture.setUp() | ||
| 311 | - | ||
| 312 | - def test_setUp_accepts_session_subclasses(self): | ||
| 313 | - class TestSession(requests.Session): | ||
| 314 | - pass | ||
| 315 | - | ||
| 316 | - self.fixture.SESSION_CLASS = TestSession | ||
| 317 | - | ||
| 318 | - self.fixture.setUp() | ||
| 319 | - | ||
| 320 | - assert self.betamax.called is True | ||
| 321 | - call_kwargs = self.betamax.call_args[-1] | ||
| 322 | - assert isinstance(call_kwargs['session'], TestSession) | ||
| 323 | - | ||
| 324 | - def test_tearDown_calls_stop(self): | ||
| 325 | - recorder = mock.Mock() | ||
| 326 | - self.fixture.recorder = recorder | ||
| 327 | - | ||
| 328 | - self.fixture.tearDown() | ||
| 329 | - | ||
| 330 | - recorder.stop.assert_called_once_with() | ||
| 331 | -- | ||
| 332 | 2.35.5 | ||
| 333 | |||
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..e3c5e7a3ac 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,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=61c15f0c146c5fb1a8ce8ba2f310d73c" | |||
| 5 | 5 | ||
| 6 | SRC_URI += " \ | 6 | SRC_URI += " \ |
| 7 | file://run-ptest \ | 7 | file://run-ptest \ |
| 8 | file://0001-Drop-ptests-fixtures-and-recorde_modes.patch \ | ||
| 8 | " | 9 | " |
| 9 | 10 | ||
| 10 | SRC_URI[md5sum] = "b8182d43a200fc126a3bf7555626f964" | 11 | SRC_URI[md5sum] = "b8182d43a200fc126a3bf7555626f964" |
