-
-
Notifications
You must be signed in to change notification settings - Fork 12k
ENH: Add tester for pytest. #10827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add tester for pytest. #10827
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is reliable in the presence of .pth files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that whole function is ugly, and inherited from nosetester. When Scipy switched the code was gone and things are done like so:
from scipy._lib._testutils import PytestTester
test = PytestTester(__name__)
del PytestTester
Which is nicely explicit. Going that way is a possibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main problem with doing it the scipy way is tracking the develop vs release switch. However, I think that can be internalized into the test runner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one reason develop vs release wasn't internalized before was downstream packages were using it for testing. I think we should stop the practice of supporting downstream packages when we switch to pytest because it has caused back compatibility problems. We should be able to change numpy testing without worrying about downstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that the new pytest based test command should be based on a function/class that's not publicly exposed; it's easy for other packages to provide their own (see SciPy's _testutils.py).
Would indeed like to keep develop vs release behavior, that is useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, the whole filtering business is kind of tricky to get right.... let me think some more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My conclusion: I think we will need those warning filters in SciPy and other projects, however not having them there now is not super critical, and they can easily be copied over. In the end we need to be free here to change this test runner for NumPy's needs without having to worry about backwards compat, so I agree with Chuck that its best to keep this class private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the conversion here? Perhaps just check instance(package, str), and throw an error of some kind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that may have been the intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to combine this with the else above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can cure that problem if we decide to simply remove the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark about casting verbose - why not just require an integer to be passed, rather than allowing floats and strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reason is to insure it is an integer and get an error if not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the intent, operator.index is a better way to spell that. I'd probably leave it without the cast though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why we need this at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May not any more. IIRC, it was because in Python 3 not all objects could be compared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just thinking that we now test against py3, so our testcase would fall afoul of this if we did it.
I suppose we might be testing for warnings in py2-only tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That and the two above were added in 82a1d81. @juliantaylor Do you recall what that was about?
NVM, that was when they were fixed up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python 2.7 run with -3 issues a lot of deprecation warnings, and we do test with that flag. After we drop 2.7 things will be easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pytest not Nose here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can go, scipy won't be using this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were mostly from Cython. IIRC, there has been some change on the Cython end, but I don't recall what it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warnings are still there I believe: https://github.com/cython/cython/blob/2032632293ccda9d3700f10c85c6be101eeb53f6/Cython/Utility/ImportExport.c#L390
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They haven't shown up in the last SciPy release, but I suspect that is because we haven't changed dtype and ufunc sizes in a while. Anyone know a handy way to check that?
|
Re: warning filters --- in pytest, the way to do this is to put this
stuff into pytest.ini
|
|
Also on "develop" and "release" --- "develop" is signaled by the
presence of our customized pytest.ini, and "release" by someone running
without our pytest.ini present.
This is something I though about when doing the Scipy conversion ---
you can try to fight the tool and try to force it to do what you want,
or do things its way. I think here "our way" of doing things is not
that superior, so it's probably not worth the hassle.
So I would just dump the "raise_warnings" stuff here. The
`check_fpu_mode` above is also not necessary (it's always enabled in
conftest.py).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone know how to pull this off in a pytest.ini file?
|
@pv Do you know if the pytest warnings filters solve the Python problems that |
How does that work? Looks like SciPy includes |
|
As I understand, suppress_warnings is only needed if you want to ignore
warnings in some tests but need to catch them in others. However, here
the whole testsuite is contained in the same suppress_warnings context,
and it's not clear any of these warnings is something that needs to be
caught in any test.
Regarding py3kwarning --- these do not appear important for numpy
development, and they can be ignored unconditionally in the ini file.
Note that the situation here is different from nosetester --- that's
used also by 3rd party projects, but this class is specific to numpy.
Yes, for scipy pytest.ini is only in the source directory. In
particular, pytest does not look for configuration files inside the
package (also, I was not able to figure out a non-horrible way to force
it to).
|
|
suppress_warnings has been in use in scipy, and I don't remember any
problems with it and what pytest does.
|
|
|
|
Another reason to avoid putting anything into the PytestTester class is
that at least for me it was desirable to minimize the differences
between `pytest --pyarg numpy` and `numpy.test()`. The pytest people
seem to prefer the former for running tests.
|
|
We do test in python 2.7 with |
|
The other option for `-3` is to ignore those warnings unconditionally
-- they are presumably not emitted when not running with -3, so
ignoring them always does no harm.
|
Hmm, currently our ci tests work by running |
Yes definitely keep. There are many scenarios where this works better, e.g. on Windows most command lines will not have scripts on the path but do have a separate menu entry for starting an IPython Qt console or Jupyter notebook (default for Anaconda I believe). Also passing in non-default commands is easier by inspecting test() and having sane keywords ( |
|
@rgommers One of the reasons I am asking is that |
|
I'm missing some context, why would we need a |
|
For scipy, pytest.ini is used e.g. for turning warnings into errors --- the release vs. dev is not based on version number. It also avoids magic in |
|
Hmm, somehow I had missed that file completely.
It's not done at all it seems? Shouldn't the removal of |
|
Is there a 16 character length limit for messages in works does not. Anyone know of a workaround? |
|
@rgommers If you look at the top of the output from runtests.py, you see the file |
|
@rgommers: pytest does not look for the ini file inside the installed package (and it's not shipped in the first place). I think it works fine as it's now -- error on warning is enabled if you run the tests inside the source tree (or explicitly specify the config file). @charris: the second field I think is a regexp, so do () need to be quoted? |
The "bench" testing with the old bench files is no longer supported. These days we use `runtests.py` and `asv`.
Include relevant suppression of various warnings.
[ci skip] This is not used yet, but has been tested with temporary changes and works.
59c2bd9 to
fddaa7c
Compare
|
Updated. |
|
@charris, filtering globally is only fine if you never want to test that warning anywhere. Which is probably OK for things like those funny cython warnings, but not OK for anything that numpy warns itself. Otherwise "once" filters/default is always problematic (if you may want to test the warning). "ignore" filters should be fine once we drop 2.7 probably (since I guess the older py3s are also gone then). Maybe just to note |
|
Re: pytest + the context, I do not see how it can do real issues. It really is just a I agree with @pv, as also said above, the most outer level of |
|
@seberg OK, I think we are good, with only ignore filters up top, and most of those will go away with Python 2.7. I don't recall exactly why we are testing the |
|
I'm going to put this in as it has no effect on current NumPy. Thanks all. |
Okay, I see how it works. Looks good, the only thing to keep in mind is that we shouldn't put warning filters in |
|
We actually have a deprecation warning on integer divisions with the -3 flag set. It is a deprecation warnig So, it does not matter much anyway, the only thing that might make a bit sense is to say that "numpy: classical int division" should not be ignored, but the test will fail if it is, so... |
This PR does two things
__init__files, it isn't used anymorepytest.inifile.pytesttester.pythat providesPytestTesterfor pytest testing.Actual testing with pytest will wait on another PR, but the new pytesttester has been tested to work as well as can be expected without the full suite of changes to come.
This PR is for getting the code under review. It is possible to combine it with the final switch to pytest if desired, but this is an opportunity to examine the addition in isolation.