Skip to content

Restored beta warn checks #7282

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/test-linux-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ jobs:
# Run Tests
python3 -m torch.utils.collect_env
python3 -m pytest --junitxml=test-results/junit.xml -v --durations 20

# Specific test for warnings on "from torchvision.datasets import wrap_dataset_for_transforms_v2"
# We keep them separate to avoid any side effects due to warnings / imports.
# TODO: Remove this and add proper tests (possibly using a sub-process solution as described
# in https://github.com/pytorch/vision/pull/7269).
python3 test/check_v2_dataset_warnings.py
35 changes: 35 additions & 0 deletions test/check_v2_dataset_warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import warnings

import torchvision


def test_warns_if_imported_from_datasets():
with warnings.catch_warnings(record=True) as w:
from torchvision.datasets import wrap_dataset_for_transforms_v2

assert callable(wrap_dataset_for_transforms_v2)

assert len(w) == 2
assert "torchvision.transforms.v2" in str(w[-1].message)


def test_no_warns_if_imported_from_datasets():

torchvision.disable_beta_transforms_warning()

with warnings.catch_warnings():
warnings.simplefilter("error")

from torchvision.datasets import wrap_dataset_for_transforms_v2

assert callable(wrap_dataset_for_transforms_v2)

from torchvision.datasets import cifar

assert hasattr(cifar, "CIFAR10")


if __name__ == "__main__":
# We can't rely on pytest due to various side-effects, e.g. conftest etc
test_warns_if_imported_from_datasets()
test_no_warns_if_imported_from_datasets()
4 changes: 2 additions & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import pytest
import torch
import torchvision
from common_utils import CUDA_NOT_AVAILABLE_MSG, IN_FBCODE, IN_OSS_CI, IN_RE_WORKER, OSS_CI_GPU_NO_CUDA_MSG


torchvision.disable_beta_transforms_warning()

from common_utils import CUDA_NOT_AVAILABLE_MSG, IN_FBCODE, IN_OSS_CI, IN_RE_WORKER, OSS_CI_GPU_NO_CUDA_MSG
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This prevents warnings from v2 imported in common_utils

Copy link
Member

Choose a reason for hiding this comment

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

Good catch!



def pytest_configure(config):
# register an additional marker (see pytest_collection_modifyitems)
Expand Down