Comment 3 for bug 1231492

Revision history for this message
Corey Goldberg (coreygoldberg) wrote :

> Note that the browser test case does the required cleanup
> and shuts down the test server in its tearDown() method,
> so I don't think the issue is there.

it might not always get called.

in the autopilot tests of webbrowser-app, both 'BrowserTestCaseBase' and 'BrowserTestCaseBaseWithHTTPServer' use tearDown() funtions. It would be more robust to add these as cleanups rather than teardowns.

tearDown is only called if the setUp() succeeds, whereas a cleanup is called unconditionally. (cleanups were new in Python 2.7's unittest, and also exist in testtools.TestCase)

see http://docs.python.org/3/library/unittest.html#unittest.TestCase.addCleanup

so if a setUp() fails somewhere after the server is started, the tearDown will not be called, leaving a hanging server process around.

for example, in 'BrowserTestCaseBaseWithHTTPServer' class, you could rename tearDown() to cleanup() (or whatever), and inside the setUp, add:

`self.addCleanup(cleanup)`

this would make it more robust and possibly alleviate this issue.

p.s. if this wasn't explained clearly, I can MP a fix to webbrowser-app changing from tearDowns to addCleanups.
the TestCase class I'm referring to reside in /tests/autopilot/webbrowser_app/tests/__init__.py of webbrowser-app.

-cgoldberg