refguide-check with pytest as a runner#26604
Conversation
numpy/conftest.py
Outdated
| msg = "|".join(msgs) | ||
|
|
||
| with warnings.catch_warnings(): | ||
| warnings.filterwarnings('ignore', category=DeprecationWarning, message=msg) |
There was a problem hiding this comment.
The full tests have a check that doesn't like this, although the error mesage is bad, I think it's supposed to say something like we don't want to let code in that might filter a real warning. Obviously you need to ignore warnings to implement this context manager. Maybe there's a way to dynamically add pytest.mark.filterwarnings marks to a test? Another option is to manually add an exception for this use-case.
There was a problem hiding this comment.
Let me do the simplest thing and skip the top level conftest.py in that test.
The conftest is needed to get the smoke-docs configuration from the main conftest. To run doctesting, use (this is scipy's `smoke-tutorial`) $ pytest --doctest-glob=*rst ~/repos/numpy/doc/source/user/ -v
|
Okay, the last commit adds a Curiously, somewhere in the spin machinery warnings get turned into errors by default. I wonder where this switch is. EDIT: this is fixed, all warnings are filtered out. |
|
Thanks so much for working on this. I know at some point @seberg was looking at adding docstring checking with pytest-doctest-plus. Just a head's up in case that intersects with this change. Can we get a mention of this in the developer guide too? |
|
Thanks Nathan!
I think at this stage I'm going to pause working on this, and ask for an exec decision. |
Yeah, it would be nice to consolidate the ecosystem more and doctestplus seemed/seems like the more likely candiate for that, but I don't think that should stop improvements here either way. |
Follow what pytest --doctest-modules allows: - directories - -k patterns `pytest --doctest-modules path/to/py/file` I'd expect to work, but apparently it fails to collect anything --- and this is not related to scipy-doctests.
|
Okay, the PR is ready from my side.
|
Makes sense, perhaps we should make a decision which way we wish to go. #21070 seems to have a few parallel discussions:
Issue #21069 also discussed transparency of which doctests are running. Issue #15845 suggested moving to doctest-plus, but also did not reach a conclusion. |
|
Well, we never used doctests to check the code for correctness only to check the docs for correctness. That is right IMO since docs should change freely without worrying about code test coverage. OTOH, that argument doesn't mean you can't just run the doctests always: docs getting out-dated isn't much better than code tests starting to fail. However, I suspect doctests are more flaky (e.g. we never run them on 32bit platforms, I bet and I am not sure if they might be python version sensitive more than other tests).
Thanks, but I suppose I don't see that I am OK with this largely as it is, it isn't like the |
To summarize main high-level difference between scipy-doctest and doctestplus (+opinionated comments): Architecture:
UI:
Overall, all features of scipy-doctest can be added to doctestplus. I'm on record suggesting an ecosystem wide solution, #21070 (comment). That discussion went nowhere though, which is why there is now a |
There is some discussion in scipy/scipy#20127. Perusing unit tests as extended examples --- definitely yes, it's likely not just you and me doing this regularly :-). |
|
I think Edit: maybe |
|
Added to |
mattip
left a comment
There was a problem hiding this comment.
We discussed this at the triage meeting, and this got a thumbs-up. The only nit is if we could change the name to check-docs. I took the liberty of changing the name.
|
Just to be clear: this does not completely replace refguide-check since it does not check the rst documentation, correct? So the circle ci job running refguide-check should still be running as previously. |
|
Indeed. This is on my to do list. Scipy's ui is |
Sounds fine to me, good to keep it consistent.
A followup is fine if you're ok with that. I'd like to be able to have the new |
|
I agree with Sebastian that doctests are not tests. They are examples that happen to be tested. A good documentation example is not a good test and a good test is not a good documentation example. They shouldn't be confused with each other. The point of doctests is just to ensure documentation examples actually work the way they say they do. But that seems irrelevant to the question of whether something like |
|
So how about landing it as is, and I'll work on a follow-up to
Not sure how to make |
I honestly don't care for that and if you want something that checks everything, it may have to also include linting? And that would make it a new invocation, which is probably fine if we can think of it, like
Ah, I somewhat expected it would. FWIW, I might be happy to include the |
Sounds like a plan, thanks! |
|
Thanks @ev-br |
|
FWIW: I view doctest as a way to test the documentation for correctness. So it is a "test". Documentation can have bugs just like code can have bugs, and testing is just one tool to expose those bugs. Relegating documentation tests to a category that is "not testing" does a disservice to the hard work put into making the documentation. That said, it is true the examples in the documentation are meant to be "happy path" demonstrations of correct use of the functionality, and should not be taken as comprehensive tests to prove correctness of the code, so the goal of examples is not the same as the goal of unit tests. |
Yes, I agree completely, and that's part of my argument that this should be easier to invoke. I just want to push back from the idea that a doctest is a test, because that leads to people writing bad documentation examples (not to accuse anyone here of saying that, but I've seen it happen before). |
|
|
||
| >>> np.array([1.2, object(), "hello world"], | ||
| dtype=StringDType(coerce=True)) | ||
| ... dtype=StringDType(coerce=True)) |
There was a problem hiding this comment.
This is taken over from the initial version, but should this not be coerce=False? – see also
numpy/doc/source/user/basics.strings.rst
Lines 185 to 188 in a1f2d58
There was a problem hiding this comment.
Yes, but it seems already fixed.
There was a problem hiding this comment.
- Sorry, must have looked at the wrong branch then – in
mainand 2.2.x it's stillTrue.
There was a problem hiding this comment.
Sorry, confusing that this is twice in the docs, and only once is wrong. Yeah, should just fix it...
There was a problem hiding this comment.
I was a bit puzzled that it did not raise in doctests, but apparently the exception was quoted incompletely.
There was a problem hiding this comment.
As the likely author of the typo (didn't check) thanks for noticing and fixing 😀
SciPy has transitioned to running refguide-check modified doctesting via pytest, and here's a matching proposal for NumPy.
The target invocation would be
Currently one needs to manually pytest-ignore several dusty corners so the precise incantation for me locally is
Of course, all these ignores could/should go into a
spincommand, which is on my TODO list.For comparison:
(Most lot of scipy complexity is filtering out warnings though)