From 12fa6f263d48fdd200601057c0f724a60b771965 Mon Sep 17 00:00:00 2001
From: tenma <tenma+swh@mailbox.org>
Date: Thu, 29 Oct 2020 14:43:52 +0100
Subject: [PATCH] core tests: disambiguate arg 'request' through typing

Both requests.Request and _pytest.FixtureRequest objects are passed to
test fixtures as argument 'request'. This hurts readability.
Adding typing annotations makes it clear which one is meant.
---
 swh/core/db/pytest_plugin.py  | 3 ++-
 swh/core/pytest_plugin.py     | 5 +++--
 swh/core/tests/test_config.py | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/swh/core/db/pytest_plugin.py b/swh/core/db/pytest_plugin.py
index 07edf270..8f5280e6 100644
--- a/swh/core/db/pytest_plugin.py
+++ b/swh/core/db/pytest_plugin.py
@@ -8,6 +8,7 @@ import logging
 import subprocess
 from typing import Optional, Set, Union
 
+from _pytest.fixtures import FixtureRequest
 import psycopg2
 import pytest
 from pytest_postgresql import factories
@@ -137,7 +138,7 @@ def postgresql_fact(
     no_truncate_tables: Set[str] = {"dbversion"},
 ):
     @pytest.fixture
-    def postgresql_factory(request):
+    def postgresql_factory(request: FixtureRequest):
         """Fixture factory for PostgreSQL.
 
         :param FixtureRequest request: fixture request object
diff --git a/swh/core/pytest_plugin.py b/swh/core/pytest_plugin.py
index 7a450197..c9da42cc 100644
--- a/swh/core/pytest_plugin.py
+++ b/swh/core/pytest_plugin.py
@@ -10,6 +10,7 @@ import re
 from typing import Dict, List, Optional
 from urllib.parse import unquote, urlparse
 
+from _pytest.fixtures import FixtureRequest
 import pytest
 import requests
 from requests.adapters import BaseAdapter
@@ -117,7 +118,7 @@ def get_response_cb(
 
 
 @pytest.fixture
-def datadir(request):
+def datadir(request: FixtureRequest) -> str:
     """By default, returns the test directory's data directory.
 
     This can be overridden on a per file tree basis. Add an override
@@ -297,7 +298,7 @@ def flask_app_client(app):
 # stolen from pytest-flask, required to have url_for() working within tests
 # using flask_app_client fixture.
 @pytest.fixture(autouse=True)
-def _push_request_context(request):
+def _push_request_context(request: FixtureRequest):
     """During tests execution request context has been pushed, e.g. `url_for`,
     `session`, etc. can be used in tests as is::
 
diff --git a/swh/core/tests/test_config.py b/swh/core/tests/test_config.py
index df310ce4..8d02b2c6 100644
--- a/swh/core/tests/test_config.py
+++ b/swh/core/tests/test_config.py
@@ -16,7 +16,7 @@ pytest_v = pkg_resources.get_distribution("pytest").parsed_version
 if pytest_v < pkg_resources.extern.packaging.version.parse("3.9"):
 
     @pytest.fixture
-    def tmp_path(request):
+    def tmp_path():
         import pathlib
         import tempfile
 
-- 
GitLab