I have something like this as a sampler:
class TestMe(object):
def test_a(self):
assert 'c' == '1'
print "I am here"
and nosetests gives me the following error correctly
nosetests test_me.py --tc-file ../configs/test_config.yaml -v
test_me.TestMe.test_a ... FAIL
======================================================================
FAIL: test_me.TestMe.test_a
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/tests/test_me.py", line 7, in test_a
assert 'c' == '1'
AssertionError
On the other hand, if I have a script like this which is also run by nosetests:
class TestMe(object):
def __init__(self):
...............
def test_b(self):
status = {'status': 'pass'} #by default
if status:
print("PASS: Connection was successful")
else:
print("FAIL: Connection was NOT successful")
status['status'] = "fail" #updating status in dictionary
return status
When I run the above with nose tests, the it says:
nosetests test_110.py --tc-file ../configs/test_config.cfg -v
test_110.TestMe.test_b ... ok
----------------------------------------------------------------------
Ran 1 test in 0.026s
OK
Whereas only when I look at the log file I know that it has failed. How can I make the failure show up on the CLI?
You can assert on status['status']=='passed' or you can raise AssertionError('connection failed')
in your failing if case statement.