Re: Repeated name of unit tests



Final explanation for this problem is simple.

inittests is a class attribute in UnitTestsObserver, for that reason is
shared by all instances of class. When something is append to this
attribute in an instance, changes in all instances of class (and none
problem using self.unittests), but if you modify it using 
self.unittests = [] (or another value), this instruction creates other
attribute into this instance but class attribute doesn't change, so when
a new class is created the previous value is kept. To change in all
instances you have to use self.__class__.unittests = [].

So, there are two solutions (in class UnitTestsObservers):

1. Don't use class attribute for this. Only left self.unittests = [] in
__init__ method and delete from here:

	class UnitTestsObserver(buildstep.LogLineObserver):
	   unittests = []       --> delete this line
	   def __init__(self):
		self.unittests = []  --> add this line

If you don't delete indicated line, all will work like if this isn't exists because 
while all references to this attribute are with self.unittests all works and class 
attribute keeps itself empty.

2. Use self.__class__.unittests = [] to restart in all instances.


I was quite confused at first because I don't know anything about Python
and its characteristics, and my problem was this too. Thanks for your
time.






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]