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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---