Re: Feedbacks and recommendations about test coverage tools
Hi, It's easy to receive test coverage information from Django tests. (See below if you search for a solution...) But is it possible to receive the same kind of coverage information from test tools like Windmill (or Selenium)? I believe, it's probably difficult because these tools execute against a server which is not in the thread covered by the testing process... Could someone give me light? Thanks in advance, Michel __ Below, you have my solution for normal test coverage: 1) You should install the very last version of coverage.py (see the reference in the previous mails-It includes colouring feature now...) 2) You should change your test runner in your setting.py: TEST_RUNNER = 'cov_runner.run_tests' COVERAGE_MODULES = ('general.views','general.utilities','goals.views','goals.models') # adapt to your stuff here... 3) Here is the content of my test runner (you can adapt to your configuration) # -*- coding: utf-8 -*- import os from django.db.models import get_app from django.conf import settings import coverage def run_tests(test_labels, verbosity=1, interactive=True, extra_tests= []): """ Run the unit tests for all the test labels in the provided list. Labels must be of the form: - app.TestClass.test_method Run a single specific test method - app.TestClass Run all the test methods in a given class - app Search for doctests and unittests in the named application. When looking for tests, the test runner will look in the models and tests modules for the application. A list of 'extra' tests may also be provided; these tests will be added to the test suite. If the settings file has an entry for COVERAGE_MODULES or test_labels is true it will prints the coverage report for modules/apps Returns number of tests that failed. """ do_coverage = hasattr(settings, 'COVERAGE_MODULES') or bool (test_labels) if do_coverage: #coverage.erase() # remove from old version cov = coverage.coverage() cov.start() from django.test import simple # os.environ['SERVER_NAME'] = 'localhost' # retval = simple.run_tests(test_labels, verbosity, interactive, extra_tests) if do_coverage: cov.stop() print '--' # try to import all modules for the coverage report. modules = [] if getattr(settings, 'COVERAGE_MODULES', None): modules = [__import__(module, {}, {}, ['']) for module in settings.COVERAGE_MODULES] elif test_labels: modules = [] for label in test_labels: pkg = _get_app_package(label) modules.extend(_package_modules(*pkg)) cov.html_report(modules, directory='../logs/covhtml') cov.report(modules) # , show_missing=1 return retval def _get_app_package(label): """Get the package of an imported module""" imp, app = [], get_app(label) path = os.path.dirname(app.__file__) path_list = path.split(os.sep) path_list.reverse() for p in path_list: imp.insert(0, p) try: pkg = __import__('.'.join(imp), {}, {}, ['']) return pkg, '.'.join(imp) except ImportError: continue def _package_modules(pkg, impstr): """Get all python modules in pkg including subpackages impstr represents the string to import pkg """ modules = [] path = pkg.__path__[0] for f in os.listdir(path): if f.startswith('.'): continue if os.path.isfile(path + os.sep + f): name, ext = os.path.splitext(f) if ext != '.py': continue #python module modules.append(__import__(impstr + '.' + name, {}, {}, [''])) elif os.path.isdir(path + os.sep + f): #subpackage imp = impstr+ '.' + f try: spkg = __import__(imp, {}, {}, ['']) modules.extend(_package_modules(spkg, imp)) except ImportError: pass return modules --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Feedbacks and recommendations about test coverage tools
Here is another interesting link: http://siddhi.blogspot.com/2007/04/code-coverage-for-your-django-code.html It's a bit old, but it points itself to other interesting links (read the comments also...) After reading and testing a bit all these things, I arrive for the moment at the conclusion that we will have some work to integrate different parts, but at the end, this will give more flexibility... I would like to be able to take into account the coverage from 'external' tests also, like web browsing or Selenium scripts... Thus I need to be able to start and stop manually the recording of coverage.py (Ned Batchelder) Hope it will be possible... On the other hand, with this approach, the integration with the Django test support is not that important... After that, it's nice to have a copy of the source coloured to see what part was covered by the tests. That can probably be done with the code mentioned in the link above. I spend (loosed) some time testing the coverage functionality in Netbeans 6.7RC... It worked a bit, but only for doctests (in my OS: ubuntu)... At the end, it don't worked anymore!! (Menu in grey!!) It was never possible to mention something like a test root directory that it maybe need to take more test into account... I still like Netbeans (for example for the integration with svn) but will stay in 6.5. That the progress on my side... And I still would really appreciate recommendations and feedbacks from experimented group members. Thanks in advance, Michel On Jun 6, 12:11 pm, kRONwrote: > Thanks for posting the links, I'll be sure to try and test it during > the weekend. > > On Jun 5, 1:37 pm, Michelschr wrote: > > > Hello everyone, > > > What are the current trends about the best test coverage tools to use > > with Django? > > Do you have feedback or recommendations for me? > > > Up to now, I founded this links: > > >http://opensource.55minutes.com/trac/browser/python/trunk/django/apps... > > > and I would be happy if I can receive some light from the community > > before digging further. > > > Thanks in advance, > > > Michel > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Feedbacks and recommendations about test coverage tools
Thanks for posting the links, I'll be sure to try and test it during the weekend. On Jun 5, 1:37 pm, Michelschrwrote: > Hello everyone, > > What are the current trends about the best test coverage tools to use > with Django? > Do you have feedback or recommendations for me? > > Up to now, I founded this links: > > http://opensource.55minutes.com/trac/browser/python/trunk/django/apps...http://pypi.python.org/pypi/django-test-coverage/ > > and I would be happy if I can receive some light from the community > before digging further. > > Thanks in advance, > > Michel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Feedbacks and recommendations about test coverage tools
Hello everyone, What are the current trends about the best test coverage tools to use with Django? Do you have feedback or recommendations for me? Up to now, I founded this links: http://opensource.55minutes.com/trac/browser/python/trunk/django/apps... http://pypi.python.org/pypi/django-test-coverage/ and I would be happy if I can receive some light from the community before digging further. Thanks in advance, Michel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---