File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,22 @@ def setUp(self):
2121 self .c = pysipfenn .Calculator ()
2222 self .assertIsNotNone (self .c )
2323
24+ def tearDown (self ):
25+ '''Release all objects created during setUp and by individual tests to prevent memory
26+ from accumulating across the test suite. Exporter attributes (``onnxexp``,
27+ ``torchexp``, ``coremlexp``) are deleted inside their respective tests on the happy
28+ path, but a mid-test failure would skip those clean-ups; the ``hasattr`` guards here
29+ ensure they are always freed. The Calculator is deleted last because the exporters
30+ hold a ``calculator`` reference into it.
31+ '''
32+ # Optional exporter objects — only present on the happy path when the test fails early
33+ for attr in ('onnxexp' , 'torchexp' , 'coremlexp' ):
34+ if hasattr (self , attr ):
35+ delattr (self , attr )
36+ # Core Calculator created in setUp
37+ del self .c
38+ gc .collect ()
39+
2440 def testInit (self ):
2541 '''Test that the Calculator object is initialised correctly.'''
2642 self .assertEqual (self .c .predictions , [])
You can’t perform that action at this time.
0 commit comments