From 7c7807165362f1dc20916ade29468f9189a908e5 Mon Sep 17 00:00:00 2001 From: Anirudh Dagar Date: Thu, 10 Jun 2021 16:58:48 +0530 Subject: [PATCH 1/2] port test_datasets_video_utils.py to pytest --- test/test_datasets_video_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_datasets_video_utils.py b/test/test_datasets_video_utils.py index 0a9d3bdfc36..0d19eb0b9b1 100644 --- a/test/test_datasets_video_utils.py +++ b/test/test_datasets_video_utils.py @@ -1,7 +1,7 @@ import contextlib import os import torch -import unittest +import pytest from torchvision import io from torchvision.datasets.video_utils import VideoClips, unfold @@ -31,7 +31,7 @@ def get_list_of_videos(num_videos=5, sizes=None, fps=None): yield names -class Tester(unittest.TestCase): +class TestVideo: def test_unfold(self): a = torch.arange(7) @@ -58,7 +58,7 @@ def test_unfold(self): ]) assert_equal(r, expected, check_stride=False) - @unittest.skipIf(not io.video._av_available(), "this test requires av") + @pytest.mark.skipif(not io.video._av_available(), reason="this test requires av") def test_video_clips(self): with get_list_of_videos(num_videos=3) as video_list: video_clips = VideoClips(video_list, 5, 5, num_workers=2) @@ -82,7 +82,7 @@ def test_video_clips(self): assert video_idx == v_idx assert clip_idx == c_idx - @unittest.skipIf(not io.video._av_available(), "this test requires av") + @pytest.mark.skipif(not io.video._av_available(), reason="this test requires av") def test_video_clips_custom_fps(self): with get_list_of_videos(num_videos=3, sizes=[12, 12, 12], fps=[3, 4, 6]) as video_list: num_frames = 4 @@ -124,7 +124,7 @@ def test_compute_clips_for_video(self): num_frames = 32 orig_fps = 30 new_fps = 13 - with self.assertWarns(UserWarning): + with pytest.warns(UserWarning): clips, idxs = VideoClips.compute_clips_for_video(video_pts, num_frames, num_frames, orig_fps, new_fps) assert len(clips) == 0 @@ -132,4 +132,4 @@ def test_compute_clips_for_video(self): if __name__ == '__main__': - unittest.main() + pytest.main([__file__]) \ No newline at end of file From b72c944c1f881f3a4dd777c16c219073abe4e0c0 Mon Sep 17 00:00:00 2001 From: Anirudh Dagar Date: Thu, 10 Jun 2021 16:59:59 +0530 Subject: [PATCH 2/2] lint: add empty line end --- test/test_datasets_video_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_datasets_video_utils.py b/test/test_datasets_video_utils.py index 0d19eb0b9b1..389ad5196af 100644 --- a/test/test_datasets_video_utils.py +++ b/test/test_datasets_video_utils.py @@ -132,4 +132,4 @@ def test_compute_clips_for_video(self): if __name__ == '__main__': - pytest.main([__file__]) \ No newline at end of file + pytest.main([__file__])