millin commented on a change in pull request #15163:
URL: https://github.com/apache/airflow/pull/15163#discussion_r611035166
##########
File path: tests/providers/elasticsearch/log/test_es_task_handler.py
##########
@@ -253,7 +253,9 @@ def test_set_context_w_json_format_and_write_stdout(self):
def test_read_with_json_format(self):
ts = pendulum.now()
- formatter = logging.Formatter('[%(asctime)s] {%(filename)s:%(lineno)d}
%(levelname)s - %(message)s')
+ formatter = logging.Formatter(
+ '[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s -
%(message)s - %(exc_text)s'
+ )
Review comment:
It failed for me without these fixes:
```
tests/providers/elasticsearch/log/test_es_task_handler.py:253
(TestElasticsearchTaskHandler.test_read_with_json_format)
[2020-12-24 19:25:00,962] {taskinstance.py:851} INFO - some random stuff -
!= some random stuff
Expected :some random stuff
Actual :[2020-12-24 19:25:00,962] {taskinstance.py:851} INFO - some random
stuff -
<Click to see difference>
self =
<tests.providers.elasticsearch.log.test_es_task_handler.TestElasticsearchTaskHandler
testMethod=test_read_with_json_format>
def test_read_with_json_format(self):
ts = pendulum.now()
formatter = logging.Formatter(
'[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s -
%(message)s - %(exc_text)s'
)
self.es_task_handler.formatter = formatter
self.es_task_handler.json_format = True
self.body = {
'message': self.test_message,
'log_id':
f'{self.DAG_ID}-{self.TASK_ID}-2016_01_01T00_00_00_000000-1',
'offset': 1,
'asctime': '2020-12-24 19:25:00,962',
'filename': 'taskinstance.py',
'lineno': 851,
'levelname': 'INFO',
}
self.es_task_handler.set_context(self.ti)
self.es.index(index=self.index_name, doc_type=self.doc_type,
body=self.body, id=id)
logs, _ = self.es_task_handler.read(
self.ti, 1, {'offset': 0, 'last_log_timestamp': str(ts),
'end_of_log': False}
)
> assert "[2020-12-24 19:25:00,962] {taskinstance.py:851} INFO - some
random stuff - " == logs[0][0][1]
E AssertionError: assert '[2020-12-24 19:25:00,962]
{taskinstance.py:851} INFO - some random stuff - ' == 'some random stuff'
log/test_es_task_handler.py:277: AssertionError
```
--
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:
[email protected]