Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests fails on admin but works with default test runner #269

Open
karimone opened this issue Aug 20, 2016 · 6 comments
Open

tests fails on admin but works with default test runner #269

karimone opened this issue Aug 20, 2016 · 6 comments

Comments

@karimone
Copy link

Hello, I already posted this error on stackexchange, but maybe is a bug.

I'm working on a Django project and we are doing some refactoring. I "promoted" an admin.py module to an admin package and I load all the splitted modules in the admin/__init__.py

Everything works fine. The admin works as expected, but the tests fail if I use nose as a TestRunner.

If I use the default tests runner everything works.

The list of some of the packages I use:

Django==1.7.7 (I can't upgrade right now)
django-nose==1.4.4
nose==1.3.7
coverage==4.2

Nose is runned with the following options:

NOSE_ARGS = [
    '--cover-html',
    '--cover-html-dir=htmlcov',
    '--cover-package=app',
    '--cover-erase',
    '--nologcapture',
]

Above the error:

======================================================================
ERROR: Failure: NotRegistered (The model CrontabSchedule is not registered)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/..../local/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/..../local/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/..../local/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/..../application/app/core/admin/__init__.py", line 6, in <module>
    from .unregister import *
  File "/..../application/app/core/admin/unregister.py", line 12, in <module>
    unregister(djcelery_models.CrontabSchedule)
  File "/..../envs/echeck/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 116, in unregister
    raise NotRegistered('The model %s is not registered' % model.__name__)
NotRegistered: The model CrontabSchedule is not registered

----------------------------------------------------------------------
Ran 128 tests in 62.824s

Any idea?

@jwhitlock
Copy link
Contributor

django-nose 1.4.4 does not support Django 1.7 or earlier. Please try with version 1.4.3.

@karimone
Copy link
Author

Thanks, I downgraded, but nothing. still the same error.

@jwhitlock
Copy link
Contributor

It appears that nose imports your modules in a different order than your app does, and the CrontabSchedule admin class is not loaded by the time you attempt to unregister it. This may very well be a side-effect of splitting admin.py into modules, and how nose scans for tests. Or, you may have some stray .pyc files that are confusing the issue.

Is this an open-source project, where I can duplicate the issue? Or, can you create a test project that demonstrates it?

@karimone
Copy link
Author

First of all, thank you for your support.

The project is not opensource, unfortunately. I tried to comments some of the loading on the init.py but nothing. I clean all the .pyc before every tests and still nothing.

At the moment the most reasonable thing to do is to revert the admin/ to admin.py it could be a problem with the django 1.7 branch, but I don't know how to proceed to debug the way nose tests the modules in my app.

I think is nose, because with the Django test runner everything works.

@karimone
Copy link
Author

I restored the old admin.py file and I get 127 tests passed.

I created again the admin/ I copied inside the folder the file admin.py and in __init__.py I added the line from admin import *

Nose fail with 128 tests. Why nose run 128 tests when I have only 127? Any idea?

@jwhitlock
Copy link
Contributor

I believe the NotRegistered error is summarized by nose as a failed test, and that's where the "extra" test is coming from.

A few things to try:

  • Adjust the order of INSTALLED_APPS in settings, changing the relative order of django_nose, djcelery, and your application
  • Wrap unregister in a try-except block, something like:
try:
   unregister(djcelery_models.CrontabSchedule)
except NotRegistered:
  pass

This won't fix the problem (and you'll have to figure out where to import NotRegistered from), but may uncover the next issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants