-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Replace unittests in providers tests by pure pytest [Wave-3]
#27696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
uranusjr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn’t read everything but nothing pops up from a few sampling.
Taragolis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add info about change logic in tests or tests helpers
| if case: | ||
| warnings.warn( | ||
| "Passing `case` has no effect and will be remove in the future. " | ||
| "Please set to `None` for avoid this warning.", | ||
| FutureWarning, | ||
| stacklevel=3, | ||
| ) | ||
|
|
||
| if not msg: | ||
| assert _trim(first) == _trim(second) | ||
| else: | ||
| assert _trim(first) == _trim(second), msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace usage unittests.TestCase.assertEqual by assert.
Because some of tests use this helper (google, amazon, apache) I add warning as a reminder for further migration to pytest.
| output = self.hook.get_file_by_pattern(TMP_PATH, "*.txt") | ||
| self.assertTrue(output, TMP_FILE_FOR_TESTS) | ||
| # In CI files might have different name, so we check that file found rather than actual name | ||
| assert output, TMP_FILE_FOR_TESTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for now I keep same logic for this test: "Returns any file without check expected".
Seems like in CI and local breeze there are different set of files as result
assert output == TMP_FILE_FOR_TESTSPass in the local environment and failed in the CI with error
E AssertionError: assert 'remote_path.txt' == 'test_file.txt'
E - test_file.txt
E + remote_path.txt
| def test_no_host_key_check_enabled(self, get_connection): | ||
| connection = Connection(login="login", host="host", extra='{"no_host_key_check": false}') | ||
| connection = Connection(login="login", host="host", extra='{"no_host_key_check": true}') | ||
|
|
||
| get_connection.return_value = connection | ||
| hook = SFTPHook() | ||
| assert hook.no_host_key_check is False | ||
| assert hook.no_host_key_check is True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix this test.
It might be a typo because it had same implementations as test_no_host_key_check_disabled initially
| @unittest.skipIf( | ||
| "AIRFLOW_RUNALL_TESTS" not in os.environ, "Skipped because AIRFLOW_RUNALL_TESTS is not set" | ||
| @pytest.mark.skipif( | ||
| "AIRFLOW_RUNALL_TESTS" not in os.environ, reason="Skipped because AIRFLOW_RUNALL_TESTS is not set" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea is variable AIRFLOW_RUNALL_TESTS set anywhere because I couldn't find any reference outside of tests in main. This variable also check in some other tests
I found that initially this env added by this PR #7468 and info about it should store into the https://issues.apache.org/jira/browse/AIRFLOW-6847 (unfortunately I do not have access).
When I tried set export AIRFLOW_RUNALL_TESTS=x in breeze and run tests I've always get same error, regardless of whether migrated to pytest or not
ERROR airflow.task:taskinstance.py:1749 Task failed with exception
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 175, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 95, in create_connection
raise err
File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 85, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 710, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/local/lib/python3.7/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1036, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 976, in send
self.connect()
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 205, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 187, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f4a91d33e10>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 499, in send
timeout=timeout,
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 788, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=3400): Max retries exceeded with url: /v1/statement (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4a91d33e10>: Failed to establish a new connection: [Errno 111] Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/airflow/airflow/sensors/base.py", line 200, in execute
poke_return = self.poke(context)
File "/opt/airflow/airflow/providers/common/sql/sensors/sql.py", line 92, in poke
records = hook.get_records(self.sql, self.parameters)
File "/opt/airflow/airflow/providers/presto/hooks/presto.py", line 152, in get_records
return super().get_records(self.strip_sql_string(sql), parameters)
File "/opt/airflow/airflow/providers/common/sql/hooks/sql.py", line 196, in get_records
return self.run(sql=sql, parameters=parameters, handler=fetch_all_handler)
File "/opt/airflow/airflow/providers/presto/hooks/presto.py", line 196, in run
return_last=return_last,
File "/opt/airflow/airflow/providers/common/sql/hooks/sql.py", line 266, in run
self._run_command(cur, sql_statement, parameters)
File "/opt/airflow/airflow/providers/common/sql/hooks/sql.py", line 291, in _run_command
cur.execute(sql_statement)
File "/usr/local/lib/python3.7/site-packages/prestodb/dbapi.py", line 236, in execute
result = self._query.execute()
File "/usr/local/lib/python3.7/site-packages/prestodb/client.py", line 542, in execute
response = self._request.post(self._sql)
File "/usr/local/lib/python3.7/site-packages/prestodb/client.py", line 356, in post
proxies=PROXIES,
File "/usr/local/lib/python3.7/site-packages/prestodb/exceptions.py", line 130, in decorated
raise error
File "/usr/local/lib/python3.7/site-packages/prestodb/exceptions.py", line 117, in decorated
result = func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 635, in post
return self.request("POST", url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 565, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=3400): Max retries exceeded with url: /v1/statement (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4a91d33e10>: Failed to establish a new connection: [Errno 111] Connection refused'))
Is it possible that this kind of tests are actually broken and just not run in CI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very likely
) (cherry picked from commit 518fd84)
) (cherry picked from commit 518fd84)
Follow-up: #26831, #26992
Attempt to replace
unittests.TestCaseby nativepytestclasses into providers tests except this:google(146 modules)amazon(88 modules)apache(33 modules)microsoft(27 modules)All changes are straight forward:
unittests.TestCaseclass andTestCase.assert*methodsparameterized.expandbypytest.mark.parametrize. I cant see any benefits if compare to builtinpytest.requests_mock.mockdecorator byrequests_mockfixture