Repository navigation
Enable Easy TestRunner Subclassing - #5505
Conversation
479f3eb to
c6cc5f8
Compare
e450f2f to
a2c4368
Compare
|
This still needs tests and some better developer documentation, but before I put that work in I would like some buy-in on the idea. Are people generally supportive of this somewhat crazy suggestion?! |
|
Is this backward compatible? How would this affect external customization like astropy/package-template#176 ? |
|
The tests pass, so I am hoping that means it's backwards compatible. What's in astropy/package-template#176 is a pytest hook right, so it would not affect the |
astrofrog
left a comment
There was a problem hiding this comment.
This is a great idea, and it would be nice to get this into 1.3. I left a few small comments - my only other comment is that if you would make use of this in SunPy or in another package, I would recommend trying to do a PR to that package now just to make sure that it will suit your needs (in case you find any fundamental design flaws with this).
| from ..utils.exceptions import AstropyWarning | ||
|
|
||
| class keyword(object): | ||
| def __init__(self, default_value, priority=0): |
There was a problem hiding this comment.
Can you make the spacing here PEP8-compliant, i.e. one more space above and below class keyword?
There was a problem hiding this comment.
Also I think it would be good to maybe add a comment or a docstring somewhere here explaining what this is for and what the priority does.
| keyword._default_value = self.default_value | ||
| keyword._priority = self.priority | ||
| keyword.__doc__ = f.__doc__ | ||
| return keyword |
There was a problem hiding this comment.
To make a decorator that preserves call signature and docstring, try instead using the wraps function from astropy.utils (rather than explicitly copying __doc__).
There was a problem hiding this comment.
wraps will not work because I explicitly use the function name below.
| package : str, optional | ||
| The name of a specific package to test, e.g. 'io.fits' or 'utils'. | ||
| If nothing is specified all default Astropy tests are run. | ||
|
|
There was a problem hiding this comment.
What about not putting extraneous spaces here and then in __new__ adding spaces if needed between parameters?
There was a problem hiding this comment.
isn't it good form to end a docstring with a blank line anyway?
There was a problem hiding this comment.
I never do... It looks weird to me. What is it with style guides and docstrings? Why not just:
"""
This is a docstring
"""
How does:
""" This is a docstring
"""
make any sense? 😛
Anyway, up to you - what I mean is more that if you don't assume that sub-classes include the whitespace, you can strip whitespace and add it back so that the output is always predictable in the generated docstring?
| all_args = [] | ||
| return [] | ||
|
|
||
| @keyword(None, priority=1) |
There was a problem hiding this comment.
When the priority is >0, it would be good to add a comment above as to why that is, and what it depends on.
|
|
||
| return [] | ||
|
|
||
| @keyword(None) |
There was a problem hiding this comment.
Can't you make the default be None and just do @keyword in those cases?
| """ | ||
| if args: | ||
| return shlex.split(args, | ||
| posix=not sys.platform.startswith('win')) |
There was a problem hiding this comment.
PEP8 gone mad - just put it one one line? :)
2c57c44 to
c9e6c2b
Compare
| """ | ||
|
|
||
| # Don't import pytest until it's actually needed to run the tests | ||
| from .helper import pytest |
There was a problem hiding this comment.
Can we put this somewhere else in this file, so we don't enforce the use of vendored pytest? (SunPy dosen't use it.)
There was a problem hiding this comment.
Good question - I'm not sure why it had to be this way. Maybe just try and put it top-level?
71fe0a5 to
9f392c7
Compare
|
Hey @Cadair I rebased your PR. One interesting side-effect is that your commits are no longer verified. Oopsie. |
9f392c7 to
a482523
Compare
|
@Cadair - this is looking great to me - If you think its done I think its basically there. One thing that's missing , though: documentation. Can you add something to the testing part of the docs that shows how someone might add this extra one? |
a482523 to
7bc7540
Compare
This actually breaks the whole point of this exercise, because it makes this class astropy specific.
If you don't want the docstring included subclass and don't set a docstring.
7bc7540 to
fb6e109
Compare
| """ | ||
| pep8 : bool, optional | ||
| Turn on PEP8 checking via the pytest-pep8 plugin and disable normal | ||
| tests. Same as specifying `--pep8 -k pep8` in `args`. |
There was a problem hiding this comment.
Here and elsewhere, you need double backticks, otherwise the Sphinx build fails looking for references
There was a problem hiding this comment.
@Cadair - a few teaks required to make the docs finish without warnings (including @astrofrog's comment above), and a couple quick additions to the docs, but then I think this is good!
| above. | ||
|
|
||
| Astropy Test Function | ||
| ##################### |
There was a problem hiding this comment.
This needs to be ^ instead of #, because Sphinx needs to have consistent section headings or else it spurts out all kinds of warnings.
| Astropy Testing helpers (`astropy.tests.helper`) | ||
| ************************************************ | ||
| *************** | ||
| Astropy Testing |
There was a problem hiding this comment.
Maybe "Astropy Testing Tools" or "Astropy Testing Machinery"? That would make it clearer that this is the machinery, while the guidelines are below.
Along the same lines, perhaps under this title (but before the helper module heading), you should add a sentence with a link to the testing guidelines. Something like This section is primarily a reference for developers that want to understand or add to the Astropy testing machinery. See :doc:/development/testguide for an overview of running or writing the tests.
| Astropy Test Runner | ||
| =================== | ||
|
|
||
| When executing tests with either `astropy.test` or ``python setup.py test`` the call to pytest is controlled by the `astropy.tests.runner.TestRunner` class. |
There was a problem hiding this comment.
Can you add a few sentences explaining the changes in this PR and maybe giving a very simple example of how to write your own test keyword? (even if it just produces "hello world").
There was a problem hiding this comment.
I put an example of writing a keyword in the docstring for TestRunnerBase, but I will add something here as well.
80cb8fe to
298df93
Compare
|
@eteq all sorted I hope. |
|
@Cadair - had to make one change in Cadair/astropy@d7d3391 - you were missing backticks around a link, but the rest looks good. Merging! |
|
@eteq - thanks for merging this! However, I noticed the following issue with this pull request:
Would it be possible to fix this? Thanks! This is an experimental bot being written by @astrofrog - let me know if the message above is incorrect! |
This PR is designed to make it simple for affiliated packages to add or remove arguments from the astropy test runner based on custom needs not shared by astropy core.
The way this works is by separating each kwarg out into a separate method which can be overloaded by a subclass or new methods added. The
__new__constructor then looks for all the methods defined on the class which have been decorated with thekeyworddecorator and adds them to a dictionary which forms the allowed keyword arguments and their default values for therun_testsmethod. Documentation is also delegated to the keyword methods.Removal of keyword arguments is supported by overloading the method and returning
NotImplemented.One (unintended) side effect of this is that the
run_testsmethod is now keyword argument only.Finally, I would be interested in extending this to automatically generate the setup.py command, that requires that command importing the TestRunner class, I don't know if that is going to break the setup.py machinery in any way?
ping @wkerzendorf @astrofrog