-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Add warnings checks for v2 namespaces #7288
Changes from all commits
b19c3c9
24d3ff7
584f637
4972fb3
020e823
7840082
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import os | ||
import random | ||
import re | ||
import textwrap | ||
import warnings | ||
from functools import partial | ||
|
||
|
@@ -24,7 +25,7 @@ | |
except ImportError: | ||
stats = None | ||
|
||
from common_utils import assert_equal, cycle_over, float_dtypes, int_dtypes | ||
from common_utils import assert_equal, assert_run_python_script, cycle_over, float_dtypes, int_dtypes | ||
|
||
|
||
GRACE_HOPPER = get_file_path_2( | ||
|
@@ -2266,5 +2267,35 @@ def test_random_grayscale_with_grayscale_input(): | |
torch.testing.assert_close(F.pil_to_tensor(output_pil), image_tensor) | ||
|
||
|
||
# TODO: remove in 0.17 when we can delete functional_pil.py and functional_tensor.py | ||
@pytest.mark.parametrize( | ||
"import_statement", | ||
( | ||
"from torchvision.transforms import functional_pil", | ||
"from torchvision.transforms import functional_tensor", | ||
"from torchvision.transforms.functional_tensor import resize", | ||
"from torchvision.transforms.functional_pil import resize", | ||
), | ||
) | ||
@pytest.mark.parametrize("from_private", (True, False)) | ||
def test_functional_deprecation_warning(import_statement, from_private): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize this is slightly overkill, we don't need |
||
if from_private: | ||
import_statement = import_statement.replace("functional", "_functional") | ||
source = f""" | ||
import warnings | ||
|
||
with warnings.catch_warnings(): | ||
warnings.simplefilter("error") | ||
{import_statement} | ||
""" | ||
else: | ||
source = f""" | ||
import pytest | ||
with pytest.warns(UserWarning, match="removed in 0.17"): | ||
{import_statement} | ||
""" | ||
assert_run_python_script(textwrap.dedent(source)) | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main([__file__]) |
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.
Did you add this for #7265 or because we actually need it for these tests. I'm not against it, but want to make sure I understand correctly.
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 is mostly a drive-by, I stole it from #7282.
I think #7278 added some v2 imports in
common_utils
and we started seeing the warnings in the test suite, so now we have to disable them before we import anything fromcommon_utils
.