Handle Celery-dependent tests in Django and with django-jenkins
So in your life, one of these days, you're going to realize you need tests, and that "maybe" you also need to test components that depend on several Celery tasks.
Well to help you make this day more productive and less painful, here's a few tips.
First to make it work with Django-celery, a pretty good but small documentation is available herehttp://ask.github.com/django-celery/cookbook/unit-testing.html it may seems small and not enough, but it actually is enough. To sum up all you need to make it work with ./manage.py testis to change the test runner to : [sourcecode language="python"] TEST_RUNNER = 'djcelery.contrib.test_runner.CeleryTestSuiteRunner' [/sourcecode]
But it's not enough, soon when you think everything's over, you'll want to deploy and make it go through Jenkins's testing processes. Well i don't know about you but to me the django-jenkins project is quite a good one and i use it everyday but it has one flaw, it already as its designated TEST_RUNNER so if you try to execute your tests through ./manage.py jenkins it won't work and you'll get at least a Connection Refusederror.
Here's how to fix this, the documentation says if you want to replace the TEST_RUNNER you may do so, but the class you'll use needs to inherit from django_jenkins.runner.CITestSuiteRunner and if you want the Celery tasks to work you need to use the djcelery.contrib.test_runner.CeleryTestSuiteRunner.
Fair enough, here's what i did. I created a new class : [sourcecode language="python"] from django_jenkins.runner import CITestSuiteRunner from djcelery.contrib.test_runner import CeleryTestSuiteRunner class MixedInTestRunner(CITestSuiteRunner, CeleryTestSuiteRunner): pass [/sourcecode]
Why not ? and used it as such defining the new TEST_RUNNER by changing the settings's variable JENKINS_TEST_RUNNER to the newly created class.
And voilà.
Newsletter
Stay updated with new articles.
Keep reading
MultiThreaded Test cases – Why ? How ? and What’s for dinner ?
Okay so to make a small introduction (i promise a tiny one) i'm starting to contribute into [VirgoRT](http://www.eclipse.org/virgo/ "Virgo OSGi Runtime") (ex-SpringSource DM Server) for me it's an opp...
Aug 13, 2010How to test and understand custom analyzers in Lucene
I've began to work more and more with the great "low-level" library [Apache Lucene](https://lucene.apache.org) created by Doug Cutting. For those of you that may not know, Lucene is the indexing and s...
Jun 20, 2013How to debug Django using the Python Debugger PDB
Even if that seems common sense, i found out that there's not that much sources that explains how to use [PDB](http://docs.python.org/library/pdb.html "Python Debugger") with Django's bundle webserver...
Mar 15, 2011
No comments yet. Be the first to comment!