-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Test setup and teardown #5336
Test setup and teardown #5336
Conversation
was not using these. Move the calls to the setup_test and teardown_test utilities into the top level conftest.py file instead, so they get used for all tests. This resulted in a number of new failures due to uncaught warnings that had to be fixed. Some uncaught warnings are still being skipped in the io module, but should be looked into further.
use np.lib.NumpyVersion rather than distutils.LooseVersion
skimage/_shared/testing.py
Outdated
@@ -201,15 +201,28 @@ def setup_test(): | |||
|
|||
warnings.simplefilter('error') | |||
|
|||
# do not error on specific warnings from the skimage.io module | |||
warnings.filterwarnings( | |||
'default', message='TiffFile:', category=DeprecationWarning, |
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.
what does this do? we need 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.
I see so this should really be open as an issue, for us to address the warnings appropriatly.
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.
Yes, I opened a new issue at #5337 just now where the specific warnings that I observed locally are listed. 3 are deprecated parameters names for tifffile
and the rest are ResourceWarning
s about unclosed image files.
Couuld you reference the pytest docs that explain the fixture you used. Do these setup/teardown get called every test? module? session? |
They are two of the hooks described under pytest_runtest_protocol. They are run for each test and will apply to all tests since this If we only want it enabled on some modules, I think we have to instead move it into a There may very well be other, better ways to do this with |
I had to add some additional warning skip cases for things that caused warnings when using the minimum dependencies. It looks like everything is passing here now (aside from one Azure timeout that seems to occur somewhat regularly in recent PRs) |
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.
Great! I've made a minor code suggestion, otherwise this is a very satisfying cleanup PR, thanks @grlee77!
Co-authored-by: Juan Nunez-Iglesias <juan.nunez-iglesias@monash.edu>
The only thing I'm worried about is the fact that warnings appear with strange combinations of software that we don't test for. Updated numpy, but old secondary library. Do we have a way of disabling test failures? Does this switch work? |
Yes, that concerns me a bit too. The question is if the annoyance of updating these outweighs the benefit of finding potential issues early. (One bug in Perhaps it should be disabled by default and only 1 or 2 CI jobs can enable the strict warning checks via an environment variable.
Good question, let me check into this. |
@grlee77 unfortunately it isn't just an "annoyance" but really puts the breaks on downstream packagers doing their job. Failing on warnings because a warning in our test suite that was addressed in Scipy 1.6 for numpy 1.20 but the particular distribution is pinned to scipy 1.5 is not fun for them. |
This Should we have a separate environment variable that controls the use of the global warnings behavior as in this PR? |
For reference, the original test setup/teardown functions that I removed from the |
Okay, I was not thinking about that case. If I change it so that these errors are disabled by default, but can be enabled upon request, than that would be fine wouldn't it? |
Yes. I would be in favor of that. |
user must request error on warnings via SKIMAGE_TEST_STRICT_WARNINGS_GLOBAL=1
This decorator's settings get overridden by pytest_runtest_setup!
clearer and avoids DeprecationWarning about \- escape char
Thanks! |
Description
closes #3439
Many of the test folders have an
__init__.py
file containing the following code:As far as I can tell,
pytest
never calls these setup or teardown methods (I added print statements and ran pytest with the-s
option, but nothing was visible). The intention of thesetup_test
method seems to have been to cause error on any warnings raised in the tests, whileteardown_test
restores the default errorstate.In this PR, I have removed all of these from the
__init__.py
files and just added it in one place in the top-levelconftest.py
file instead, where I verified that pytest does indeed call them. This has resulted in failures on a number of warnings that were previously uncaught. I fixed most of these in this PR, but there are a couple things to follow up on:1.) I did not try to address the warnings in the
skimage.io
module, but have just set them not to error for now.2.) There is a test case that fails in the viewer module (due to a call to
data.imread
, which hasn't existed for some time). I changed this toio.imread
, but the test still fails locally. Apparently this one never gets run on CI? I haven't yet looked into it further.Checklist
./doc/examples
(new features only)./benchmarks
, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py
.doc/release/release_dev.rst
.