invalid test discovery output - python

I want to test an application but it is giving this error:
Test loading failed: Error: Invalid test discovery output! (34,
'Hannibal', 5) Error: Invalid test discovery output! (34, 'Hannibal',
5) at Object.parseTestSuites
(c:\Users\Assas.vscode\extensions\syntaf.vscode-python-test-adapter-0.0.3\out\src\pytest\pytestTestCollectionParser.js:14:15)
at PytestTestRunner.
(c:\Users\Assas.vscode\extensions\syntaf.vscode-python-test-adapter-0.0.3\out\src\pytest\pytestTestRunner.js:60:56)
at Generator.next () at fulfilled
(c:\Users\Assas.vscode\extensions\syntaf.vscode-python-test-adapter-0.0.3\node_modules\tslib\tslib.js:114:62)
at process.processTicksAndRejections
(node:internal/process/task_queues:96:5)

Related

How to capture the error logs from Airflow and send it in mail?

We are trying to report the failures that occur during Airflow job execution and capture the exceptions from logs and send it in email .
Currently we display following things in the failure email written in pyt.
failure_msg = """
:red_circle: Task Failed.
*Dag*: {dag}
*Task*: {task}
*Execution Time*: {exec_date}
*Log Url*: {log_url}
""".format(
dag=context.get('task_instance').dag_id,
task=context.get('task_instance').task_id,
ti=context.get('task_instance'),
exec_date=context.get('execution_date'),
log_url=context.get('task_instance').log_url
I was looking to capture the exception message from Airflow. The above message displays high level info like dag id, task id, url etc.
Referrer below Airflow documentation but so far did not get any way to capture exact exception message.
Currently I am manually throwing error in one of the DAG as
def scan_table():
try:
raise ValueError('File not parsed completely/correctly')
logging.info(message)
except Exception as error:
raise ValueError('File not parsed completely/correctly inside exception block')
print("Error while fetching data from backend", error)
Tried using this exception=context.get('task_instance').log.exception
but it showed as
<bound method Logger.exception of <Logger airflow.task (INFO)>>
In the DAG log output in Airflow UI, the exception is thrown as:
[2023-01-04, 09:05:07 UTC] {taskinstance.py:1909} ERROR - Task failed with exception
Traceback (most recent call last):
File "/opt/bitnami/airflow/dags/git_airflow-dags/scan_table.py", line 37, in scan_table
raise ValueError('File not parsed completely/correctly')
ValueError: File not parsed completely/correctly
I want to capture this part of log and print in the failure_msg in the Python snippet.
I was able to find answer to this.
We can get access to exception thrown by Airflow using below snipped.
context.get('exception')

ValueError: not enough values to unpack (expected 2, got 1) while running django tests

Django test throws value error every time i try to input data in the test request
req_body = {"Value1":"Value1", "Value2":"Value2"}
request = self.client.get(self.getSingleData_url, data= json.dumps(req_body), content_type='application/json')
I have tried data = req_body but it returns an empty {} to the endpoint
Complete Value error
I have tried using, other ways to pass data, but once it is passed as json it throws Value Error

Python Exception block not working for MQMIError - MQRC_NO_MSG_AVAILABLE

I have wrote below exception in my Python code while doing "get" message from MQ. However when records are getting PUT on MQ by another application & at the same time I am running my code it's failing with error:
pymqi.MQMIError: MQI Error. Comp: 2, Reason 2033: FAILED: MQRC_NO_MSG_AVAILABLE
Although below exception is handled it'snot working. Can you please suggest if below exception is wrong OR provide me correct code?
except pymqi.MQMIError as e:
if e.comp == pymqi.CMQC.MQCC_FAILED and e.reason == pymqi.CMQC.MQRC_NO_MSG_AVAILABLE:
pass # No messages, that is OK, we can ignore it.
else:
raise # Some other error condition.

Unable to search message with message-ID, BAD [b'Could not parse command']

Good day everyone,
I'm working on a personal python small project here, trying to search messages with messages-id, but encounter error as below :
imaplib.error: SEARCH command error: BAD [b'Could not parse command']
this is a sample of the code :
line = '<ABCDefghIJKlmnOpqRS#mail.gmail.com>'
typ, data = mail.search(None, '(HEADER Message-ID "%s")' % line)

unexpected token '$' in pymongo program

bdnome = collection.find_one({ $text: {$search: vername}})
At this line a error appears in "$text" with the following error
"unexpected token '$'" and "unexpected toke 'text', and a error
appears in "$search" --- "unexpected token '{'" and "unexpected
token '$'" and "unexpected token 'search'", and a error occurs
as well in "vername" --- "unexpected token 'vername".
I'm working with databases in MongoDB
You are trying to use JavaScript syntax in Python. That doesn't work.
bdnome = collection.find_one({ "$text": {"$search": vername}})

Categories

Resources