Scrapy, a fast high-level web crawling & scraping framework for Python.
Fix deprecations in fixtures for pytest 9.2.0. (#8423)
Andrey Rakhmatullin71e4b2b074b3
diff --git a/pyproject.toml b/pyproject.tomlindex 89355c49c..8dc92a026 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -288,6 +288,7 @@ addopts = ["--reactor=asyncio",]xfail_strict = true+asyncio_default_fixture_loop_scope = "function"python_files = ["test_*.py", "test_*/__init__.py"]markers = ["only_asyncio: marks tests that require the asyncio loop to be used",@@ -331,6 +332,8 @@ filterwarnings = [# by message because some tox envs do not install pytest-cov, and pytest# warns when a filter names a module it cannot import."ignore:Coverage disabled via --no-cov switch!",+ # unrecognized when pytest-asyncio isn't installed+ "ignore:Unknown config option. asyncio_:pytest.PytestConfigWarning",][tool.ruff.lint]diff --git a/tests/test_downloader_handler_twisted_ftp.py b/tests/test_downloader_handler_twisted_ftp.pyindex 6c9895e2d..a20aa81bd 100644--- a/tests/test_downloader_handler_twisted_ftp.py+++ b/tests/test_downloader_handler_twisted_ftp.py@@ -63,8 +63,8 @@ class TestFTPBase(ABC):await port.stopListening()- @staticmethod@pytest.fixture+ @staticmethoddef dh() -> Generator[FTPDownloadHandler]:crawler = get_crawler()dh = build_from_crawler(FTPDownloadHandler, crawler)diff --git a/tests/utils/bases/commands.py b/tests/utils/bases/commands.pyindex 3a01488a7..9bf666545 100644--- a/tests/utils/bases/commands.py+++ b/tests/utils/bases/commands.py@@ -1,7 +1,7 @@from __future__ import annotationsfrom shutil import copytree-from typing import TYPE_CHECKING+from typing import TYPE_CHECKING, ClassVarimport pytest@@ -14,22 +14,24 @@ if TYPE_CHECKING:class TestProjectBase:"""A base class for tests that may need a Scrapy project."""- project_name = "testproject"+ project_name: ClassVar[str] = "testproject"@pytest.fixture(scope="session")- def _proj_path_cached(self, tmp_path_factory: pytest.TempPathFactory) -> Path:+ @classmethod+ def _proj_path_cached(cls, tmp_path_factory: pytest.TempPathFactory) -> Path:"""Create a Scrapy project in a temporary directory and return its path.Used as a cache for ``proj_path``."""tmp_path = tmp_path_factory.mktemp("proj")- call("startproject", self.project_name, cwd=tmp_path)- return tmp_path / self.project_name+ call("startproject", cls.project_name, cwd=tmp_path)+ return tmp_path / cls.project_name@pytest.fixture- def proj_path(self, tmp_path: Path, _proj_path_cached: Path) -> Path:+ @classmethod+ def proj_path(cls, tmp_path: Path, _proj_path_cached: Path) -> Path:"""Copy a pre-generated Scrapy project into a temporary directory and return its path."""- proj_path = tmp_path / self.project_name+ proj_path = tmp_path / cls.project_namecopytree(_proj_path_cached, proj_path)return proj_pathdiff --git a/tests/utils/bases/download_handlers_http.py b/tests/utils/bases/download_handlers_http.pyindex 45b263398..2e1988bfb 100644--- a/tests/utils/bases/download_handlers_http.py+++ b/tests/utils/bases/download_handlers_http.py@@ -1876,7 +1876,8 @@ class TestHttpProxyBase(ABC):raise NotImplementedError@pytest.fixture(scope="session")- def proxy_mockserver(self) -> Generator[ProxyEchoMockServer]:+ @staticmethod+ def proxy_mockserver() -> Generator[ProxyEchoMockServer]:with ProxyEchoMockServer() as proxy:yield proxy