You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/05/20 10:44:45 UTC

[GitHub] [airflow] kaxil commented on a change in pull request #6311: [AIRFLOW-5615] Reduce duplicated logic around job heartbeating

kaxil commented on a change in pull request #6311:
URL: https://github.com/apache/airflow/pull/6311#discussion_r427913444



##########
File path: tests/conftest.py
##########
@@ -415,3 +417,39 @@ def pytest_runtest_setup(item):
         skip_quarantined_test(item)
     skip_if_credential_file_missing(item)
     skip_if_airflow_2_test(item)
+
+
+@pytest.fixture
+def frozen_sleep(monkeypatch):
+    """
+    Use freezegun to "stub" sleep, so that it takes no time, but that
+    ``datetime.now()`` appears to move forwards
+
+    If your module under test does ``import time`` and then ``time.sleep``::
+
+        def test_something(frozen_sleep):
+            my_mod.fn_under_test()
+
+
+    If your module under test does ``from time import sleep`` then you will
+    have to mock that sleep function directly::
+
+        def test_something(frozen_sleep, monkeypatch):
+            monkeypatch.setattr('my_mod.sleep', frozen_sleep)
+            my_mod.fn_under_test()
+    """
+    freezegun_control = None
+
+    def fake_sleep(seconds):
+        nonlocal freezegun_control

Review comment:
       `nonlocal` isn't available for Py2 so if we plan to backport it, we will have to change it




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org