[Buildbot-devel] Of mock and mocking on Red Hat/Fedora systems

Gareth Armstrong gareth.armstrong at hp.com
Tue Jun 8 12:54:31 UTC 2010


Hello Folks,

This is for info on a possible name space collision for Red Hat or 
Fedora folks.  In my adventures to put together a test passing rpm build 
for BuildBot 0.8.0, I cherry picked a couple of commits for the 
MailNotifier and its unit tests from Dustin's master branch.  Those being:

5ff4d181d552f44b2c274a17a9a0b25d1915493f fix NameError by passing 
properties into createEmail

e1cfc9d95d9df49e1dca449f3cf149862774f7f9 fix tests broken in 5ff4d181

The later commit pulls in an external dependency on Mock, a mocking and 
testing library from http://www.voidspace.org.uk/python/mock/ and 
available on PyPI http://pypi.python.org/pypi/mock/.

Now for the fun part, I packaged up mock with the intention of getting 
it into Fedora or EPEL.  No probs here, one nicely packaged and 
installed python-mock rpm.

No probs until I try running BuildBot's unit tests with the installed 
python-mock rpm.

$ trial buildbot/test/unit/test_status_mail_MailNotifier.py
/usr/lib64/python2.6/site-packages/twisted/mail/smtp.py:10: 
DeprecationWarning: the MimeWriter module is deprecated; use the email 
package instead
   import MimeWriter, tempfile, rfc822
buildbot.test.unit.test_status_mail_MailNotifier
   TestMailNotifier
     test_createEmail_message_with_patch_and_log_contains_unicode ...    
[ERROR]
     test_createEmail_message_without_patch_and_log_contains_unicode ... 
[ERROR]

===============================================================================
[ERROR]: 
buildbot.test.unit.test_status_mail_MailNotifier.TestMailNotifier.test_createEmail_message_with_patch_and_log_contains_unicode

Traceback (most recent call last):
   File 
"/home/gareth/WORK/git/buildbot/master/buildbot/test/unit/test_status_mail_MailNotifier.py", 
line 40, in test_createEmail_message_with_patch_and_log_contains_unicode
     build = self.make_build()
   File 
"/home/gareth/WORK/git/buildbot/master/buildbot/test/unit/test_status_mail_MailNotifier.py", 
line 26, in make_build
     b = mock.Mock()
exceptions.AttributeError: 'module' object has no attribute 'Mock'
===============================================================================

I even modified the test_status_mail_MailNotifier.py to use
"from mock import Mock", but still no joy.

[gareth at localhost] ~/WORK/git/test/buildbot/master
$ trial buildbot/test/unit/test_status_mail_MailNotifier.py
                                                                         
[ERROR]

===============================================================================
[ERROR]: buildbot/test/unit/test_status_mail_MailNotifier.py

Traceback (most recent call last):
   File "/usr/lib64/python2.6/site-packages/twisted/trial/runner.py", 
line 651, in loadByNames
     things.append(self.findByName(name))
   File "/usr/lib64/python2.6/site-packages/twisted/trial/runner.py", 
line 460, in findByName
     return filenameToModule(name)
   File "/usr/lib64/python2.6/site-packages/twisted/trial/runner.py", 
line 95, in filenameToModule
     ret = reflect.namedAny(reflect.filenameToModuleName(fn))
   File "/usr/lib64/python2.6/site-packages/twisted/python/reflect.py", 
line 464, in namedAny
     topLevelPackage = _importAndCheckStack(trialname)
   File 
"/home/gareth/WORK/git/test/buildbot/master/buildbot/test/unit/test_status_mail_MailNotifier.py", 
line 2, in <module>
     from mock import Mock
exceptions.ImportError: cannot import name Mock
-------------------------------------------------------------------------------

FAILED (errors=1)


But python-mock was installed !!!
rpm -ql python-mock
.
/usr/lib/python2.6/site-packages/mock.py
.

So to cut a long story short, the culprit is Fedora's "mock".  That 
"Mock" takes an SRPM and builds it in a chroot and is a very groovy tool 
from building clean RPM packages.  Well it was groovy until it polluted 
Python's name space on my system.

rpm -ql mock
.
/usr/lib/python2.6/site-packages/mock
/usr/lib/python2.6/site-packages/mock/__init__.py
.


I will file a bug on Red Hat's bugzilla and see how it pans. As I said 
at the start this mail is for info.

All the best,

Gareth

-- 






More information about the devel mailing list