Skip to content

Commit 83530cf

Browse files
committed
Use @needs_cuda instead of pyest.mark.needs_cuda
1 parent 061fefd commit 83530cf

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

test/smoke_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
import torch
55

6-
from test.utils import assert_tensor_close_on_at_least
6+
from test.utils import assert_tensor_close_on_at_least, needs_cuda
77

88
from torchcodec import ffmpeg_major_version
99
from torchcodec._frame import AudioSamples, Frame, FrameBatch
@@ -337,7 +337,7 @@ def test_video_and_audio_chunked(self, tmp_path):
337337
# TODO: validate audio on a mostly lossless codec?
338338
assert decoded_samples.sample_rate == sr
339339

340-
@pytest.mark.needs_cuda
340+
@needs_cuda
341341
def test_cuda_encoding(self, tmp_path):
342342
if ffmpeg_major_version == 4:
343343
pytest.skip("CUDA encoding not supported with FFmpeg 4")

test/test_encoders.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
NASA_AUDIO_MP3,
2525
NASA_AUDIO_MP3_44100,
2626
NASA_VIDEO,
27+
needs_cuda,
2728
needs_ffmpeg_cli,
2829
psnr,
2930
SINE_MONO_S32,
@@ -1347,7 +1348,7 @@ def test_extra_options_utilized(self, tmp_path, profile, colorspace, color_range
13471348
assert metadata["color_range"] == color_range
13481349

13491350
@needs_ffmpeg_cli
1350-
@pytest.mark.needs_cuda
1351+
@needs_cuda
13511352
@pytest.mark.parametrize("method", ("to_file", "to_tensor", "to_file_like"))
13521353
@pytest.mark.parametrize(
13531354
("format", "codec"),
@@ -1765,7 +1766,7 @@ def test_write_frames_mismatched_dimensions_errors(self, tmp_path, method, devic
17651766
with pytest.raises(RuntimeError, match="same dimensions"):
17661767
video.add_frames(frames_512)
17671768

1768-
@pytest.mark.needs_cuda
1769+
@needs_cuda
17691770
@pytest.mark.parametrize("method", ("to_file", "to_file_like"))
17701771
def test_write_frames_different_devices_errors(self, tmp_path, method):
17711772
cpu_frames = torch.randint(0, 256, (2, 3, 256, 256), dtype=torch.uint8)
@@ -1789,7 +1790,7 @@ def test_write_frames_different_devices_errors(self, tmp_path, method):
17891790
with pytest.raises(RuntimeError, match="same device"):
17901791
video.add_frames(cpu_frames)
17911792

1792-
@pytest.mark.needs_cuda
1793+
@needs_cuda
17931794
@pytest.mark.parametrize("method", ("to_file", "to_file_like"))
17941795
def test_device_None_respects_default_device(self, tmp_path, method):
17951796
source_decoder = VideoDecoder(str(TEST_SRC_2_720P.path))
@@ -1835,7 +1836,7 @@ def test_device_torch_device_object(self, tmp_path, method):
18351836
)
18361837
assert decoded_frames.shape == frames.shape
18371838

1838-
@pytest.mark.needs_cuda
1839+
@needs_cuda
18391840
@pytest.mark.parametrize("method", ("to_file", "to_file_like"))
18401841
def test_device_cuda_0_string(self, tmp_path, method):
18411842
source_decoder = VideoDecoder(str(TEST_SRC_2_720P.path))
@@ -1862,7 +1863,7 @@ def test_device_cuda_0_string(self, tmp_path, method):
18621863
)
18631864
assert decoded_frames.shape == source_frames.shape
18641865

1865-
@pytest.mark.needs_cuda
1866+
@needs_cuda
18661867
@pytest.mark.parametrize("method", ("to_file", "to_file_like"))
18671868
def test_write_samples_on_cuda_errors(self, tmp_path, method):
18681869
enc, _, open_kwargs = self._create_encoder(method, tmp_path, "wav")
@@ -2058,7 +2059,7 @@ def test_add_audio_and_video_and_encode(self, tmp_path, format, method):
20582059
atol=0.1 if format == "mkv" else 0.01,
20592060
)
20602061

2061-
@pytest.mark.needs_cuda
2062+
@needs_cuda
20622063
@pytest.mark.skipif(in_fbcode(), reason="NVENC not available in fbcode")
20632064
@pytest.mark.parametrize("method", ("to_file", "to_file_like"))
20642065
def test_cuda_video_with_cpu_video_and_cpu_audio(self, tmp_path, method):
@@ -2965,7 +2966,7 @@ def test_pixel_format_errors(self, method, tmp_path):
29652966
):
29662967
self._open_encoder(enc2, open_kwargs2)
29672968

2968-
@pytest.mark.needs_cuda
2969+
@needs_cuda
29692970
@pytest.mark.skipif(in_fbcode(), reason="NVENC not available in fbcode")
29702971
@pytest.mark.parametrize("method", ("to_file", "to_file_like"))
29712972
def test_pixel_format_gpu_override_errors(self, method, tmp_path):
@@ -3485,7 +3486,7 @@ def test_fragmented_mp4_truncation(self, format, method, tmp_path):
34853486
)
34863487

34873488
@needs_ffmpeg_cli
3488-
@pytest.mark.needs_cuda
3489+
@needs_cuda
34893490
@pytest.mark.skipif(in_fbcode(), reason="NVENC not available in fbcode")
34903491
@pytest.mark.parametrize("method", ("to_file", "to_file_like"))
34913492
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)