简体   繁体   中英

Testing in python

I want to create tests which are dependent on each other. That is the return value of one function (test case) should be used in other testcase.

I have tried using unittest and nose tests but unable to have functions which returns values and use them.

Are there any testing frameworks , which allow me to do so ?

UPDATE :

The test which i want to perform is as follows :

def setup():
 //Some initializations

def func(id):
    //some operations
     assert ' ' not in name

def test_mine:
    for loop of command line inputs 
         /////
         assert id > 0 
         if (some condition)
            for loop 
                yield func(id)

         else
            yield func(id)

So to be able to make func() a separate test case , i need to get the id which im unable to do

In general, it's best to make tests as repeatable and rigid as possible (think functional programming), and as isolated as possible. You don't want side effects to outlast a test's teardown because they may affect the results of future tests. There may be tests where some randomness may be involved (tests involving thread serialization, for instance), but without further information, it's hard to give good, concrete advise.

However, let's say you have a method m1 which returns varying results for the same arguments, and depending on those return values, you wish to call and test either m2 and m3. You could easily put all of that within a single test case and condition assertions about m2 and m3 based on the return value of m1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM