1

Given a test case:

import unittest
import mock

class TestTest(unittest.TestCase):
  def test_test(self):
    print dir(__import__('google'))
    with mock.patch('google.appengine.api.urlfetch.fetch'):
      pass

-

$ nosetests --with-gae --processes=0
Ran 1 test in 0.187s
OK

-

$ nosetests --with-gae --processes=1
======================================================================
ERROR: test_test (test_test.TestTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/sadovnychyi/example/test_test.py", line 8, in test_test
    with mock.patch('google.appengine.api.urlfetch.fetch'):
  File "/usr/local/lib/python2.7/site-packages/mock.py", line 1252, in __enter__
    self.target = self.getter()
  File "/usr/local/lib/python2.7/site-packages/mock.py", line 1414, in <lambda>
    getter = lambda: _importer(target)
  File "/usr/local/lib/python2.7/site-packages/mock.py", line 1102, in _importer
    thing = _dot_lookup(thing, comp, import_path)
  File "/usr/local/lib/python2.7/site-packages/mock.py", line 1092, in _dot_lookup
    return getattr(thing, comp)
AttributeError: 'module' object has no attribute 'appengine'
-------------------- >> begin captured stdout << ---------------------
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'net']

Any idea why its happening and how to fix it?

Dmytro Sadovnychyi
  • 6,171
  • 5
  • 33
  • 60

2 Answers2

1

So I missed a line in nosegae.py:

del sys.modules['google']

Which is fixed already to reload(sys.modules['google'])

https://github.com/Trii/NoseGAE/commit/82fe8b4cb2c037ffd441fa5bed8a6b84a066bbd2

The issue is gone.

Dmytro Sadovnychyi
  • 6,171
  • 5
  • 33
  • 60
0

AttributeError: 'module' object has no attribute 'appengine'

This suggests the GAE SDK is not properly located.

Check your SDK installation/usage instructions, python path, directory structure, IDE settings (if you use one) - depending on how you're planning to use the SDK.

Also the unittest/mock instructions (I can't comment on them - haven't used them yet).

You could try symlink-ing the 'google' SDK subdir in /Users/sadovnychi/example for example - but I can't tell if this is a good suggestion for your setup.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • Of course I've checked everything you mentioned, and its works fine with multi processing turned off. – Dmytro Sadovnychyi Apr 17 '15 at 14:23
  • Ah, I missed that aspect. But the fact that it's fundamentally an SDK module access issue remains. I suspect some missing nose multiprocessing config/setup, but I know nothing about it. – Dan Cornilescu Apr 17 '15 at 15:51