in Python by
How to Creating a Test Project in Python?

▼ Show 1 Answer

0 votes
For creating a test module, let's create a new project named Project2 similar to Project1.

Create sub folders proj and test inside Project2.

Create two empty files named inside proj and test folders respectively.

Create a copy of Project1/proj/ and place it in Project2/proj/

Add the line all = ['sample_module'] to Project2/proj/ file.

Creating a Test Module

Create an empty test module named inside test folder.

Add the following code to Project2/test/

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

Add the line all = ['test_module1'] to Project2/test/ file.

Running a Test Module

Now you can run all the tests in test module with the below command.

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


Syntax for running a Test class is slightly different from unittest as shown below. Here you use : instead of ..

nosetests test.test_module1:Testadd2num -v

And a single test can be run as shown below.

nosetests test.test_module1:Testadd2num.test_sum_2pos_num -v
Learn More with Madanswer

Related questions

0 votes
asked Jul 2, 2020 in Python by GeorgeBell