← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1154058] Re: Cannot run test_migrations.py: circular import in glance/db/sqlalchemy

 

** Changed in: glance
       Status: Fix Committed => Fix Released

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to Glance.
https://bugs.launchpad.net/bugs/1154058

Title:
  Cannot run test_migrations.py: circular import in glance/db/sqlalchemy

Status in OpenStack Image Registry and Delivery Service (Glance):
  Fix Released

Bug description:
  If I run test_migrations.py  solely, I face a problem.

  $ nosetests test_migrations.py
  E
  ======================================================================
  ERROR: Failure: ImportError (cannot import name models)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "/tmp/.venv/lib/python2.6/site-packages/nose/loader.py", line 390, in loadTestsFromName
      addr.filename, addr.module)
    File "/tmp/.venv/lib/python2.6/site-packages/nose/importer.py", line 39, in importFromPath
      return self.importFromDir(dir_path, fqname)
    File "/tmp/.venv/lib/python2.6/site-packages/nose/importer.py", line 86, in importFromDir
      mod = load_module(part_fqname, fh, filename, desc)
    File "/tmp/glance/glance/tests/unit/test_migrations.py", line 42, in <module>
      from glance.db.sqlalchemy import models
    File "/tmp/glance/glance/db/sqlalchemy/models.py", line 30, in <module>
      import glance.db.sqlalchemy.api
    File "/tmp/glance/glance/db/sqlalchemy/api.py", line 35, in <module>
      from glance.db.sqlalchemy import models
  ImportError: cannot import name models

  ----------------------------------------------------------------------
  Ran 1 test in 0.001s

  FAILED (errors=1)

  The thing is that api.py depends on models.py that depends on api.py.
  Import statements in these files are such that api.py must be imported
  before models.py. That's why usually test_migrations doesn't fail when
  all tests are launched. However, thus test_migration _depends on test
  running order_ making testing procedure unreliable, including parallel
  testing.

  If you import models.py the first, you will face circular import
  problem.

  The bug is easy to fix (see explanations in http://effbot.org/zone
  /import-confusion.htm): just move glance.db.sqlalchemy.api import to
  the only place where it's required in models.py.

To manage notifications about this bug go to:
https://bugs.launchpad.net/glance/+bug/1154058/+subscriptions