Page MenuHomePhabricator

AttributeError in setup.py breaks bot tests in Python 2
Closed, ResolvedPublic

Description

While testing for PyPy in setup.py, using the following, bot tests starts failing on Python 2.x builds.

try:
    sys.pypy_version_info
    PYPY = True
except AttributeError:
    PYPY = False

It fails because bot_tests.py includes a guard like exc = sys.exc_info()[0]; self.assertIsNone(exc)

Worth noting that while there are other try: except: blocks in setup.py, they are successful imports of multiprocessing, unittest2, bz2 in the Travis environment.

This has exposed the problem that BaseBot.exit() uses sys.exc_info(), which could be a very old stale exception on Python 2. BaseBot has some logic to avoid exceptions during the bot run from remaining in sys.exc_info(), but it doesnt clear the exceptions from before the bot run.

This isnt actually a likely bug in BaseBot or existing subclasses in bot.py, because it only looks for whether the old exception is KeyboardInterrupt, and it very unusual to have one of those caught and remaining in sys.exc_info (i.e. something permanently discarded KeyboardInterrupt, which would be bizarre) before the bot was run.

However it is very likely that new subclasses, or future improvements in BaseBot, will use sys.exc_info() for other types of exceptions, and not be expecting old exceptions from before the bot was run.

To make it more reliable, BaseBot.run() should clear the old exception before it commences process.

Related Objects

Event Timeline

Change 291523 had a related patch set uploaded (by John Vandenberg):
Clear exceptions in BaseBot.run before processing

https://gerrit.wikimedia.org/r/291523

Change 291523 merged by jenkins-bot:
Clear exceptions in BaseBot.run before processing

https://gerrit.wikimedia.org/r/291523