Skip to content

Reintroduce skimage.test utility#5909

Merged
hmaarrfk merged 8 commits intoscikit-image:mainfrom
grlee77:add-skimage-test
Oct 19, 2021
Merged

Reintroduce skimage.test utility#5909
hmaarrfk merged 8 commits intoscikit-image:mainfrom
grlee77:add-skimage-test

Conversation

@grlee77
Copy link
Contributor

@grlee77 grlee77 commented Oct 18, 2021

Description

resolves #3569 by reintroducing skimage.test. Users can run tests via

import skimage
skimage.test()

or for a specific modules with more verbose output:

import skimage
skimage.test(tests=['skimage.color', 'skimage.exposure'], verbose=2)

I had one test failure locally in a viewer plugin test that involved the camera image. The issue seems to be that these tests are getting skipped on CI so we never updated the expected value when we updated the camera image.

As suggested by @hmaarrfk in #3569, GHA should run the tests via skimage.test() for the sdist test case.

Checklist

  • Docstrings for all functions
  • Gallery example in ./doc/examples (new features only)
  • Benchmark in ./benchmarks, if your changes aren't covered by an
    existing benchmark
  • Unit tests
  • Clean style in the spirit of PEP8
  • Descriptive commit messages (see below)

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.

Prior to the conversion to pytest users could import skimage and then run the tests via
skimage.test(). This PR restores that behavior, copying an existing approach based on a
PytestTester class from NumPy.

Tests for a single submodule can be run using:
skimage.test(['skimage.color'])
This test case does not seem to have been updated when we updated the camera image
@grlee77 grlee77 added 🔧 type: Maintenance Refactoring and maintenance of internals ⏩ type: Enhancement Improve existing features labels Oct 18, 2021
@grlee77 grlee77 requested review from hmaarrfk and stefanv October 18, 2021 19:33
@pep8speaks
Copy link

pep8speaks commented Oct 18, 2021

Hello @grlee77! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 29:1: E402 module level import not at top of file

Comment last updated at 2021-10-19 01:45:26 UTC

Copy link
Member

@stefanv stefanv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Greg, this is perfect.

Without this change, 'python setup.py sdist' fails with a circular import
unless _remap.pyx has already been compiled
@stefanv
Copy link
Member

stefanv commented Oct 18, 2021

Nice, that last commit will be helpful for the lazy loading PR as well!

@grlee77
Copy link
Contributor Author

grlee77 commented Oct 18, 2021

Now it is failing because we don't require pytest in our runtime requirements, but pytest._shared.testing.py does require it.

We could move PytestTester to a different location, or I can see about delaying the import of pytest in that file.

@stefanv
Copy link
Member

stefanv commented Oct 18, 2021

Can we just do def test(): ... and import it in there?

…ytest

add git date and hash to __version__ in dev builds
@grlee77
Copy link
Contributor Author

grlee77 commented Oct 18, 2021

Can we just do def test(): ... and import it in there?

The issue was the following lines predating this PR:

import pytest
from ._warnings import expected_warnings
SKIP_RE = re.compile(r"(\s*>>>.*?)(\s*)#\s*skip\s+if\s+(.*)$")
skipif = pytest.mark.skipif
xfail = pytest.mark.xfail
parametrize = pytest.mark.parametrize
raises = pytest.raises
fixture = pytest.fixture

We only ever import from skimage._shared.testing from within test_*.py functions. In this PR, I was instead importing from that file in __init__.py which lead to the problem. I just moved the tester class to a separate tester.py file to get around that.

@grlee77
Copy link
Contributor Author

grlee77 commented Oct 18, 2021

MacOS failures look unrelated:

Warning, treated as error:
/Users/runner/work/scikit-image/scikit-image/doc/source/index.rst:14:toctree contains reference to nonexisting document 'api/api'

update: I suspect that this is related given that other recent PRs passed. I suspect the change to __version__ broke the doc build because now I see the following in the log:
*WARNING* API documentation not generated: Installed version does not match source version

@stefanv
Copy link
Member

stefanv commented Oct 19, 2021

Looks good to me; @hmaarrfk ?

[tag for tag in __version__.split('+')
if not tag.startswith('git')]
)
__version__ += f'+git{git_date}.{git_hash}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not want to use this as our new version? This is strange reporting different versions for different ways of testing the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's probably a good idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

na, this is ok. this checks for dev in the version. I think it is fine.

@hmaarrfk hmaarrfk merged commit b2901bf into scikit-image:main Oct 19, 2021
@hmaarrfk
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⏩ type: Enhancement Improve existing features 🔧 type: Maintenance Refactoring and maintenance of internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bring back skimage.test

4 participants