From de32824a6279fc742a00c68dec64b002a98e6348 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 26 Jun 2024 14:34:34 +0200 Subject: [PATCH] [IMP] *: move the `page` helper fixture to the shared conftest Use it in `test_limit` instead of direct `requests` calls. --- conftest.py | 9 +++++++++ forwardport/tests/test_limit.py | 9 +++------ runbot_merge/tests/conftest.py | 10 ---------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/conftest.py b/conftest.py index 9572cea3..99b824e5 100644 --- a/conftest.py +++ b/conftest.py @@ -385,6 +385,15 @@ def port(): s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) return s.getsockname()[1] +@pytest.fixture +def page(port): + with requests.Session() as s: + def get(url): + r = s.get('http://localhost:{}{}'.format(port, url)) + r.raise_for_status() + return r.content + yield get + @pytest.fixture(scope='session') def dummy_addons_path(): with tempfile.TemporaryDirectory() as dummy_addons_path: diff --git a/forwardport/tests/test_limit.py b/forwardport/tests/test_limit.py index 3e7bb9ed..1dd76980 100644 --- a/forwardport/tests/test_limit.py +++ b/forwardport/tests/test_limit.py @@ -1,5 +1,4 @@ import pytest -import requests from utils import seen, Commit, make_basic, to_pr @@ -9,7 +8,7 @@ from utils import seen, Commit, make_basic, to_pr pytest.param('b', 'b', 0, id='current'), pytest.param('b', 'a', 0, id='earlier'), ]) -def test_configure_fp_limit(env, config, make_repo, source, limit, count, port): +def test_configure_fp_limit(env, config, make_repo, source, limit, count, page): prod, other = make_basic(env, config, make_repo, statuses="default") with prod: [c] = prod.make_commits( @@ -35,15 +34,13 @@ def test_configure_fp_limit(env, config, make_repo, source, limit, count, port): assert not descendants.limit_id, "descendant should not inherit the limit explicitly" # check that the basic thingie works - r = requests.get(f'http://localhost:{port}/{prod.name}/pull/{pr.number}.png') - assert r.ok, r.text + page(f'/{prod.name}/pull/{pr.number}.png') if descendants: c = env['runbot_merge.branch'].search([('name', '=', 'c')]) descendants.limit_id = c.id - r = requests.get(f'http://localhost:{port}/{prod.name}/pull/{pr.number}.png') - assert r.ok + page(f'/{prod.name}/pull/{pr.number}.png') def test_ignore(env, config, make_repo, users): """ Provide an "ignore" command which is equivalent to setting the limit diff --git a/runbot_merge/tests/conftest.py b/runbot_merge/tests/conftest.py index f75447ca..b663a688 100644 --- a/runbot_merge/tests/conftest.py +++ b/runbot_merge/tests/conftest.py @@ -1,19 +1,9 @@ import pytest -import requests @pytest.fixture() def module(): return 'runbot_merge' -@pytest.fixture -def page(port): - s = requests.Session() - def get(url): - r = s.get('http://localhost:{}{}'.format(port, url)) - r.raise_for_status() - return r.content - return get - @pytest.fixture def default_crons(): return [