This is an automated email from the ASF dual-hosted git repository.

husseinawala pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new ef0ab856e4 Support type checking for third-party pytest's fixtures 
(#37457)
ef0ab856e4 is described below

commit ef0ab856e444f248c9304a26174310e09585b766
Author: Andrey Anshin <[email protected]>
AuthorDate: Thu Feb 15 23:46:01 2024 +0400

    Support type checking for third-party pytest's fixtures (#37457)
---
 tests/conftest.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tests/conftest.py b/tests/conftest.py
index 3f7e640884..5e3a4115c4 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1291,3 +1291,26 @@ def configure_warning_output(config):
 
 
 # End of modified code from  
https://github.com/athinkingape/pytest-capture-warnings
+
+if TYPE_CHECKING:
+    # Static checkers do not know about pytest fixtures' types and return,
+    # In case if them distributed through third party packages.
+    # This hack should help with autosuggestion in IDEs.
+    from pytest_mock import MockerFixture
+    from requests_mock.contrib.fixture import Fixture as RequestsMockFixture
+    from time_machine import TimeMachineFixture
+
+    # pytest-mock
+    @pytest.fixture
+    def mocker() -> MockerFixture:
+        ...
+
+    # requests-mock
+    @pytest.fixture
+    def requests_mock() -> RequestsMockFixture:
+        ...
+
+    # time-machine
+    @pytest.fixture  # type: ignore[no-redef]
+    def time_machine() -> TimeMachineFixture:
+        ...

Reply via email to