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
DM-40817: Allow skipping modules in ImportTestCase #173
Conversation
4151d6e
to
12d4430
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #173 +/- ##
==========================================
+ Coverage 94.28% 94.30% +0.01%
==========================================
Files 46 46
Lines 3169 3180 +11
==========================================
+ Hits 2988 2999 +11
Misses 181 181
☔ View full report in Codecov by Sentry. |
150e3e3
to
a8c4c99
Compare
Do we actually support python 3.9? There's a strange error that doesn't occur with python 3.10 or 3.11 and I am not sure if I should dig deep into this. |
a8c4c99
to
9ec39ba
Compare
The error on 3.9 seems to be an interaction between
None of these options are more than a few lines to fix. My philosophy for utils is that, given it's a very low level package, I try to support as old a python as I can until I get annoyed by doing so. |
I think my preference is to see if importlib_resources works on 3.9. import sys
if sys.version_info < (3, 10, 0):
import importlib_resources as resources
else:
from importlib import resources or something and see if that fixes it. (will need importlib_resources added as dependency to pyproject.toml and requirements.txt and I don't think there is a way to only make that happen on 3.9 distros) |
|
||
def test_import(self): | ||
"""Test that we can import utils.""" | ||
import import_test # noqa: F401 |
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.
This import might be a no-op depending on what other tests have already run. (pkg_resources used to import parent classes as it went but I'm not sure if importlib.resources does so)
python/lsst/utils/tests.py
Outdated
SKIP_MODULES: ClassVar[Mapping[str, Iterable[str]]] = {} | ||
"""Modules to be skipped importing as key-value pairs. | ||
|
||
The key is the package name and the value is a set of module names to skip. |
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.
Is "module name" the right word here? Aren't these file names? ie you are requiring the .py
extension.
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 could change it to SKIP_FILES
. While on that, I should also change the type of the value to be Container[str]
, since I only need in
to work.
python/lsst/utils/tests.py
Outdated
@@ -43,7 +43,11 @@ | |||
import unittest | |||
import warnings | |||
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence | |||
from importlib import resources | |||
import sys |
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.
Remove.
from importlib import resources | ||
import sys | ||
if sys.version_info < (3, 10, 0): | ||
import importlib_resources as resources |
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 importlib_resources
has to be added as a dependency to pyproject.toml and requirements.txt
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.
from importlib import resources
seems to work in python3.9
anyway. Does that have a different behavior despite the same name?
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.
It's not the same name. It's different. importlib_resources
is a PyPI package that allows older pythons to use the newer implementation of importlib.resources
. That's why I was saying that you need to add importlib_resources
as a dependency in pyproject.toml and requirements.txt.
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.
importlib.resources
was working fine on python 3.9 until you caused it trouble by asking it to scan that package inside the tests directory. The reason I'm asking you to try importlib_resources
on python 3.9 is that they might have fixed a bug in that area which explains why it worked fine on 3.10.
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.
Okay, this patch works! Thanks Tim, will clean up the changes, address the other minor comments and merge.
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.
Some minor comments.
607d4d1
to
c643c4b
Compare
@@ -346,6 +351,12 @@ class ImportTestCase(unittest.TestCase): | |||
PACKAGES: ClassVar[Iterable[str]] = () | |||
"""Packages to be imported.""" | |||
|
|||
SKIP_FILES: ClassVar[Mapping[str, Container[str]]] = {} |
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.
Don't forget to change the doc string.
c643c4b
to
413e2b0
Compare
Checklist
doc/changes