in Python by
Q:
What all nose testing tools exist in Python?

▼ Show 1 Answer

0 votes
by
nose contains few methods and tools useful for test automation, in nose.tools module.

nose has it's own assert method i.e assert_equals in nose.tools.

Usage of assert_equals is shown in below example by modifying definition of test_sample_nosetest in test_sample_module.py.

def test_sample_nose1test():

    assert_equals('HELLO','hello'.upper())

Usage of OK_ and EQ_

nose.tools also contain methods ok_ and eq_, which function similar to assert and assert_equals respectively.

You can optionally pass an error message that can be displayed when a test fails.

Usage of ok_ and eq_ is shown in below example by defining two functions in sample_test_module.py

from nose.tools import ok_, eq_

def test_using_ok():

    ok_(2+3==5)

def test_using_eq():

    eq_(2+3, 5)

Usage of 'raises' decorator

raises decorator is used to decorate those tests, which are expected to raise an Exception.

The test will be successful only if the exception raised is present in list of exceptions passed to raises decorator.

A sample test added to test_sample_module.py is shown below.

from nose.tools import raises

@raises(TypeError)

def test_using_raises():

    eq_(2+'3', 5)
Python
Learn More with Madanswer

Related questions

0 votes
0 votes
asked Jul 2, 2020 in Python by GeorgeBell
...