-
Notifications
You must be signed in to change notification settings - Fork 138
Destructor not executed after execution of a single test #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't think this is a bug. There is no documented behavior that one implementation should prevail. If you have important resources that need to be cleaned up; that's what the |
Thanks for your comment. But lets add e.g. a static instance count to to dummy object import xmlrunner
import unittest
class dummy(object):
count = 0
def __init__(self, inst):
self.inst = inst
dummy.count += 1
print("ctro, inst %s, count %d"%(inst, dummy.count))
def __del__(self):
dummy.count -= 1
print("dtro, inst %s, count %d"%(self.inst, dummy.count))
class test_spuCfgParser(unittest.TestCase):
def test_foo(self):
print("test_foo")
dummyInst = dummy("foo")
raise AssertionError("SomeError")
def test_foofoo(self):
print("test_foofoo")
dummyInst = dummy("foofoo")
raise AssertionError("SomeError")
if __name__ == '__main__':
#unittest.main()
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'), failfast=False, buffer=False, catchbreak=False) output:
I definitely do not expect that there is an instance of dummy saved somewhere in the background. Therefore this is a bug to me. |
https://docs.python.org/2/reference/datamodel.html#object.__del__ This is not a bug; the traceback is holding references to local variables. You can either use |
Running a test with the xml test runner differs from running a test with the default text runner. In the default setup after each test local objects are deleted. With the xml test runner the destructors are called after test completion. It is important to rise an assertionError in the test to get this error.
Output with unittest.main():
Output with xmlrunner:
The text was updated successfully, but these errors were encountered: