From 0ad106f57241273fd8ba0bc5317913f998a45905 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 4 Jan 2022 18:51:48 +0000 Subject: [PATCH] =?UTF-8?q?Mark=20`client`=20fixture=20as=20=E2=80=98priva?= =?UTF-8?q?te=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No tests are now using the `client` fixture directly so we can rename it. Python convention is to use an `_underscore` for things which should be considered semi private. This should discourage people from writing new tests with these old fixtures. New tests should always use `client_request`. Want to be logged in with a different user? Call `client_request.login(user)` first. Don’t want to be logged in? Call `client_request.logout()` first (most of our tests need to be logged in). Need an instance of `Response` object not an instance of `BeautifulSoup`? Use `client_request.get_response` or `client_request.post_response`. Need to pass in a URL, not arguments to `url_for`? Use `client_request.get_url(…)` or `client_request.post_url(…)`. Need to pass in a URL and get a response back? Use `client_request.get_response_from_url(…)` or `client_request.post_response_from_url(…)`. --- tests/conftest.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 88bbd81a3..fda7e4779 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2732,21 +2732,27 @@ def mock_send_notification(mocker, fake_uuid): @pytest.fixture(scope='function') -def client(notify_admin): +def _client(notify_admin): + """ + Do not use this fixture directly – use `client_request` instead + """ with notify_admin.test_request_context(), notify_admin.test_client() as client: yield client @pytest.fixture(scope='function') def _logged_in_client( - client, + _client, active_user_with_permissions, mocker, service_one, mock_login ): - client.login(active_user_with_permissions, mocker, service_one) - yield client + """ + Do not use this fixture directly – use `client_request` instead + """ + _client.login(active_user_with_permissions, mocker, service_one) + yield _client @pytest.fixture