Python Unit testing backup statics -


i'm trying unit test in python have troubles statics attributes.
problem is: python doesn't backup static attributes entails test acts unpredictable. here example code:

def test1(self):     self.assertisnone(myclass.var)     config.var = "it works"     self.assertequals("it works", myclass.var)  def test2(self):     self.assertisnone(myclass.var) # fails     config.var = "it works really"     self.assertequals("it works really", myclass.var) 

in given case can avoid resetting value either when end of first test reached or setup() , teardown() in situation not (it hard example). want make script static attributes of classes automatically i'm used in php.

i run unit tests nose (nosetests path_to_tests) switch "testing framework" if needed to.

i'm not sure why want avoid using setup() , teardown() functions, whatever reason, preventing building own pseudo-setup function? example:

def test1(self):     myclass.prep()     self.assertisnone(myclass.var)     config.var = "it works"     self.assertequals("it works", myclass.var)  def test2(self):     myclass.prep(var="whatever")     self.assertisnone(myclass.var) # fails     config.var = "it works really"     self.assertequals("it works really", myclass.var)  def prep(self, var="temp", var2="temp2"):     myclass.var = var     myclass.var2 = var2  

i've done before in cases wanted external device testing disable itself. built function go turn off , in whatever tests wanted in, run "prep" function ensure test worked. if test worked, right before finishing, call prep function again turn device on.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -