Skip to content

Destructor not executed after execution of a single test #105

Closed
@buster3

Description

@buster3

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.

import xmlrunner
import unittest

class dummy(object):
    def __init__(self, inst):
        self.inst = inst
        print("ctro, inst %s"%inst)

    def __del__(self):
        print("dtro, inst %s"%self.inst)

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 with unittest.main():

test_foo
ctro, inst foo
Fdtro, inst foo
test_foofoo
ctro, inst foofoo
Fdtro, inst foofoo

Output with xmlrunner:

Running tests...
----------------------------------------------------------------------
FF
======================================================================
FAIL [0.000s]: test_foo (__main__.test_spuCfgParser)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "debugxmlrunner.py", line 17, in test_foo
    raise AssertionError("SomeError")
AssertionError: SomeError

Stdout:
test_foo
ctro, inst foo

======================================================================
FAIL [0.000s]: test_foofoo (__main__.test_spuCfgParser)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "debugxmlrunner.py", line 23, in test_foofoo
    raise AssertionError("SomeError")
AssertionError: SomeError

Stdout:
test_foofoo
ctro, inst foofoo

----------------------------------------------------------------------
Ran 2 tests in 0.000s

FAILED (failures=2)

Generating XML reports...
dtro, inst foofoo
dtro, inst foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions