def test_sample_nosetest():
assert 'HELLO' == 'hello'.upper()
python -m nose sample_nose_test.py
Output
.
----------------------
Ran 1 test in 0.000s
OK
- For verbose output use
-v option at the end.
python -m nose sample_nose_test.py -v
Output
sample_nose_test.test_sample_nosetest ... ok
-------------------------
Ran 1 test in 0.001s
OK
- You can also run the test module using
nosetests command as shown below.
nosetests sample_nose_test.py -v
from proj.sample_module import add2num
class Testadd2num:
def test_sum_2pos_num(self):
assert add2num(6, 7)==13
def test_sum_1pos_and_1neg_num(self):
assert add2num(-10, 9)==-1
nosetests test.test_module1 -v
Verbose Output
test.test_module1.Testadd2num.test_sum_1pos_and_1neg_num ... ok
test.test_module1.Testadd2num.test_sum_2pos_num ... ok
----------------------------
Ran 2 tests in 0.002s
OK
nosetests test.test_module1:Testadd2num -v
- A single test can be run as shown below.
nosetests test.test_module1:Testadd2num.test_sum_2pos_num -v
def test_sample_nose1test():
assert_equals('HELLO','hello'.upper())
from nose.tools import ok_, eq_
def test_using_ok():
ok_(2+3==5)
def test_using_eq():
eq_(2+3, 5)
from nose.tools import raises
@raises(TypeError)
def test_using_raises():
eq_(2+'3', 5)
No comments:
Post a Comment