pytest-testinfra icon indicating copy to clipboard operation
pytest-testinfra copied to clipboard

AssertionError message to nagios output

Open sercanyaldiz opened this issue 5 years ago • 1 comments

Hello I have a simple test where I print the filename if the file exists.

/home/nagios/monitoring-env/bin/pytest -v -s -qq --nagios --tb long --inputfile=test.txt /usr/local/ncpa/plugins/test_myinfra.py

input file: test.txt
File Found: '/usr/local/ncpa/plugins/test.txt'
TESTINFRA OK - 1 passed, 0 failed, 0 skipped in 0.06 seconds

In nagios I do see the print statement: File Found: '/usr/local/ncpa/plugins/test.txt'

I have a simple assert in my code; assert len(list_match)==1 , " File NOT Found:" + str(list_match).strip('[]')

If i run the test without nagios I do see the AssertionError

/home/nagios/monitoring-env/bin/pytest -v -s --inputfile=test.txt /usr/local/ncpa/plugins/test_myinfra.py

E       AssertionError: File NOT Found: '/usr/local/ncpa/plugins/test.txt'

TESTINFRA CRITICAL - 0 passed, 1 failed, 0 skipped in 0.10 seconds

How can I have the AssertionError message displayed in Nagios when running the command below?

/home/nagios/monitoring-env/bin/pytest -v -s -qq --nagios --tb long --inputfile=test.txt /usr/local/ncpa/plugins/test_myinfra.py
TESTINFRA CRITICAL - 0 passed, 1 failed, 0 skipped in 0.06 seconds

sercanyaldiz avatar Nov 16 '20 12:11 sercanyaldiz

@philpep would you have a look at this request please ?

sercanyaldiz avatar Nov 20 '20 13:11 sercanyaldiz