On Fri, Jul 11, 2014 at 3:34 AM, Larry Martell <larry.mart...@gmail.com> wrote:
> I am trying to upgrade a site to 1.6. I read the change notes about > the tests now having to start with test. > > My project's structure is this: > > myproj/app/appname/tests > > and in that dir was a file called EventLog.py, and in that file a > function called EventLogTest > > My __init__ had: > > from myproj.app.appname.tests.EventLog import EventLogTest > > I would run the test with: > > manage.py test appname.EventLogTest > > I reanmed EventLog.py to testEventLog.py, and I also changed it in the > __init__ file to: > > from myproj.app.appname.tests.testEventLog import EventLogTest > > Then I tried: > > manage.py test appname.EventLogTest > > ImportError: No module named appname > > manage.py test app.appname.EventLogTest > > ImportError: No module named app > > manage.py test myproj.app.appname.EventLogTest > > AttributeError: 'module' object has no attribute 'EventLogTest' > > manage.py test myproj.app.appname.tests.EventLogTest > > AttributeError: 'module' object has no attribute 'tests' > > > What simple, stupid thing I am doing wrong here? What do I have to do > to run my tests in 1.6? > It depends where you're coming from, and how long you need your project to last. If you've got a working Django 1.5 project, and you just need to get it into 1.6 as fast as possible, then just add TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner' to your settings file, and you're done. Your 1.6 test suite will run exactly the same as it does in 1.5, and there won't be any change to the way your test suite runs - no changes to the way the tests are found, and no change to the way you execute them. That means: * If you've got a tests *package*, you'll have to put a bunch of imports in the tests/__init__.py module so that all the test classes are sitting in the appname.tests namespace * When you run a test, you run one of: - manage.py test appname - manage.py test appname.TestClassName - manage.py test appname.TestClassName.test_this_feature However, if you want to upgrade to the "new" behaviour in 1.6, you need to make other changes. The "new" test runner doesn't require the imports in tests/__init__.py. It does automated discovery of file in those submodules named test*.py. If your tests aren't in files with "discoverable" names, you'll need to either rename the files (and directories), or manually point manage.py test at the right filenames. If you've got a newly-structured test suite, then invoking tests is slightly different, too: - manage.py test appname - manage.py test appname.tests.test_submodule.TestClassName - manage.py test appname.tests.test_submodule.TestClassName.test_this_feature That is, you give the fully qualified Python module name of a test class, not just the 'app name.classname' simplification. See https://docs.djangoproject.com/en/dev/topics/testing/overview/#running-tests for more details, including details of how to include files other than test_*. As an aside - if you want your project to be long lived, you'll *eventually* need to make these naming changes to your test suite. It's just a question of whether you need to do it *right now*. The old approach will still work in 1.6; it will also work in 1.7, but will be more noisy. In 1.8, the DjangoTestSuiteRunner will be removed completely. So, if you want your project test suite to last until Django 1.8 and beyond, you'll ultimately need to make these changes. I hope that helps. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJxq8487HEOV6vj2Untt9ANrUuo%2BY7uOEWqUasLArVpXatMYug%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.