Mercurial > p > roundup > code
comparison test/pytest_patcher.py @ 5111:1c94afabb2cb
Fix mark_class decorator to work in all cases
The 'mark_class' decorator assumed that all test functions started with
'test_' which is the common naming convention these days. The roundup
codebase predates many of the current common conventions though though,
so many tests don't include the underscore. We now correctly check for
any test function starting with 'test' and also ensure the 'mark_class'
will also work with functions as well as classes.
This has been tested will all package dependencies missing, and all the
tests correctly skip. All the tests also pass a full test run without
any tests being skipped. A smattering of other runs of individual test
files and enabled dependencies seem to indicate that all skipping should
work as expected now.
| author | John Kristensen <john@jerrykan.com> |
|---|---|
| date | Thu, 30 Jun 2016 12:38:23 +1000 |
| parents | 43a1f7fe39f5 |
| children |
comparison
equal
deleted
inserted
replaced
| 5110:87b0358790ed | 5111:1c94afabb2cb |
|---|---|
| 22 name=f.func_name, | 22 name=f.func_name, |
| 23 argdefs=f.func_defaults, | 23 argdefs=f.func_defaults, |
| 24 closure=f.func_closure) | 24 closure=f.func_closure) |
| 25 | 25 |
| 26 def mark(cls): | 26 def mark(cls): |
| 27 if isinstance(cls, types.FunctionType): | |
| 28 return marker(copy_func(cls)) | |
| 29 | |
| 27 for method in dir(cls): | 30 for method in dir(cls): |
| 28 if method.startswith('test_'): | 31 if method.startswith('test'): |
| 29 f = copy_func(getattr(cls, method)) | 32 f = copy_func(getattr(cls, method)) |
| 30 setattr(cls, method, marker(f)) | 33 setattr(cls, method, marker(f)) |
| 31 return cls | 34 return cls |
| 32 return mark | 35 return mark |
