airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kengo Seki (JIRA)" <>
Subject [jira] [Created] (AIRFLOW-2705) Move class-level moto decorator to method-level
Date Sun, 01 Jul 2018 22:34:00 GMT
Kengo Seki created AIRFLOW-2705:

             Summary: Move class-level moto decorator to method-level
                 Key: AIRFLOW-2705
             Project: Apache Airflow
          Issue Type: Bug
          Components: redshift, tests
            Reporter: Kengo Seki
            Assignee: Kengo Seki

In tests/contrib/hooks/ and tests/contrib/sensors/,
moto decorators are at class-level, whereas they are at method-level in other tests using

class TestRedshiftHook(unittest.TestCase):

I found it can affect other tests using HTTP request. Let's say the following test is added
to tests/hooks/

    def test_sample(self):

This test sends a GET request to and succeeds of course:

$ ./ tests.hooks.test_http_hook:TestHttpHook.test_sample


/home/sekikn/a3/lib/python3.5/site-packages/urllib3/ InsecureRequestWarning:
Unverified HTTPS request is being made. Adding certificate verification is strongly advised.
Ran 1 test in 0.189s


But strangely, it fails with ConnectionError when it's executed after tests/contrib/hooks/
or tests/contrib/sensors/

$ ./ tests.contrib.hooks.test_redshift_hook tests.hooks.test_http_hook:TestHttpHook.test_sample


ERROR: test_sample (tests.hooks.test_http_hook.TestHttpHook)
Traceback (most recent call last):
  File "/home/sekikn/dev/incubator-airflow/tests/hooks/", line 250, in test_sample
  File "/home/sekikn/dev/incubator-airflow/airflow/hooks/", line 119, in run
    return self.run_and_check(session, prepped_request, extra_options)
  File "/home/sekikn/dev/incubator-airflow/airflow/hooks/", line 167, in run_and_check
    raise ex
  File "/home/sekikn/dev/incubator-airflow/airflow/hooks/", line 159, in run_and_check
    allow_redirects=extra_options.get("allow_redirects", True))
  File "/home/sekikn/a3/lib/python3.5/site-packages/requests/", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/sekikn/a3/lib/python3.5/site-packages/moto/packages/responses/",
line 308, in unbound_on_send
    return self._on_request(adapter, request, *a, **kwargs)
  File "/home/sekikn/a3/lib/python3.5/site-packages/moto/packages/responses/",
line 250, in _on_request
    raise response
requests.exceptions.ConnectionError: Connection refused: GET
-------------------- >> begin captured stdout << ---------------------
[2018-06-30 09:41:21,029] {} INFO - Using connection to:
[2018-06-30 09:41:21,030] {} INFO - Sending 'GET' to url:
[2018-06-30 09:41:21,030] {} WARNING - Connection refused: GET
Tenacity will retry to execute the operation

--------------------- >> end captured stdout << ----------------------
-------------------- >> begin captured logging << --------------------
airflow.utils.log.logging_mixin.LoggingMixin: INFO: Using connection to:
airflow.hooks.http_hook.HttpHook: INFO: Sending 'GET' to url:
airflow.hooks.http_hook.HttpHook: WARNING: Connection refused: GET
Tenacity will retry to execute the operation
--------------------- >> end captured logging << ---------------------

Ran 7 tests in 1.838s

FAILED (errors=1)

This problem is solved by using method-level moto decorator instead of class-level one. I
suspect class-level decorator patches method that sends HTTP request and doesn't restore the
original state.

This message was sent by Atlassian JIRA

View raw message