I ended up doing a quick proof of concept that works pretty well:
_ROUTES_TESTED = {}
def tests_routes(*args):
"""
`@tests_routes` is a decorator
when writing/editing a test, declare what routes the test covers, like
such:
@tests_routes(("foo", "bar"))
def test_foo_bar(self):
...
this will populate a global variable `_ROUTES_TESTED` with the name of
the
tested routes.
invoking the Audit test:
python -m unittest tests.FunctionalTests_AuditRoutes
will ensure all routes in Pyramid have test coverage
"""
_routes = args[0]
if isinstance(_routes, (list, tuple)):
for _r in _routes:
_ROUTES_TESTED[_r] = True
else:
_ROUTES_TESTED[_routes] = True
def _decorator(_function):
def _wrapper(*args, **kwargs):
_function(*args, **kwargs)
return _wrapper
return _decorator
class FunctionalTests_AuditRoutes(AppTest):
"""
python -m unittest tests.FunctionalTests_AuditRoutes
"""
def test_audit(self):
pyramid_route_names = [i.name for i in self.testapp.app.
routes_mapper.routelist]
names_missing = [r for r in pyramid_route_names if r not in
_ROUTES_TESTED.keys()]
if names_missing:
raise ValueError("no coverage for %s routes: %s" % (len(
names_missing), names_missing))
This still needs work, but implementing this into the test suite of an app
with 150+ routes, I found 20 without test coverage
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/ad28fe5b-6c78-4a5d-9a09-ccffb18d2805%40googlegroups.com.