Skip to content

Commit 451189e

Browse files
author
Molly Xu
committed
remove tests from collection
1 parent 1ea235a commit 451189e

File tree

5 files changed

+108
-64
lines changed

5 files changed

+108
-64
lines changed

test/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
import pytest
55
import torch
66

7+
from .utils import in_fbcode
8+
79

810
def pytest_configure(config):
911
# register an additional marker (see pytest_collection_modifyitems)
1012
config.addinivalue_line(
1113
"markers", "needs_cuda: mark for tests that rely on a CUDA device"
1214
)
15+
config.addinivalue_line(
16+
"markers", "needs_ffmpeg_cli: mark for tests that rely on ffmpeg"
17+
)
1318

1419

1520
def pytest_collection_modifyitems(items):
@@ -28,6 +33,15 @@ def pytest_collection_modifyitems(items):
2833
# 'needs_cuda' mark, and the ones with device == 'cpu' won't have the
2934
# mark.
3035
needs_cuda = item.get_closest_marker("needs_cuda") is not None
36+
needs_ffmpeg_cli = item.get_closest_marker("needs_ffmpeg_cli") is not None
37+
has_skip_marker = item.get_closest_marker("skip") is not None
38+
has_skipif_marker = item.get_closest_marker("skipif") is not None
39+
40+
if in_fbcode():
41+
# fbcode doesn't like skipping tests, so instead we just don't collect the test
42+
# so that they don't even "exist", hence the continue statements.
43+
if needs_ffmpeg_cli or has_skip_marker or has_skipif_marker:
44+
continue
3145

3246
if (
3347
needs_cuda

test/test_decoders.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
NASA_AUDIO_MP3_44100,
4040
NASA_VIDEO,
4141
needs_cuda,
42+
needs_ffmpeg_cli,
4243
psnr,
4344
SINE_MONO_S16,
4445
SINE_MONO_S32,
@@ -1312,10 +1313,7 @@ def setup_frame_mappings(tmp_path, file, stream_index):
13121313
# Return the custom frame mappings as a JSON string
13131314
return custom_frame_mappings
13141315

1315-
@pytest.mark.skipif(
1316-
in_fbcode(),
1317-
reason="ffprobe not available internally",
1318-
)
1316+
@needs_ffmpeg_cli
13191317
@pytest.mark.parametrize("device", all_supported_devices())
13201318
@pytest.mark.parametrize("stream_index", [0, 3])
13211319
@pytest.mark.parametrize(
@@ -1362,10 +1360,7 @@ def test_custom_frame_mappings_json_and_bytes(
13621360
),
13631361
)
13641362

1365-
@pytest.mark.skipif(
1366-
in_fbcode(),
1367-
reason="ffprobe not available internally",
1368-
)
1363+
@needs_ffmpeg_cli
13691364
@pytest.mark.parametrize("device", all_supported_devices())
13701365
@pytest.mark.parametrize(
13711366
"custom_frame_mappings,expected_match",

test/test_encoders.py

Lines changed: 81 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
assert_tensor_close_on_at_least,
1818
get_ffmpeg_major_version,
1919
get_ffmpeg_minor_version,
20-
in_fbcode,
2120
IS_WINDOWS,
2221
NASA_AUDIO_MP3,
22+
needs_ffmpeg_cli,
2323
psnr,
2424
SINE_MONO_S32,
2525
TEST_SRC_2_720P,
@@ -217,13 +217,22 @@ def test_bad_input_parametrized(self, method, tmp_path):
217217
getattr(decoder, method)(**valid_params, num_channels=num_channels)
218218

219219
@pytest.mark.parametrize("method", ("to_file", "to_tensor", "to_file_like"))
220-
@pytest.mark.parametrize("format", ("wav", "flac"))
220+
@pytest.mark.parametrize(
221+
"format",
222+
[
223+
pytest.param(
224+
"wav",
225+
marks=pytest.mark.skipif(
226+
get_ffmpeg_major_version() == 4,
227+
reason="Swresample with FFmpeg 4 doesn't work on wav files",
228+
),
229+
),
230+
"flac",
231+
],
232+
)
221233
def test_round_trip(self, method, format, tmp_path):
222234
# Check that decode(encode(samples)) == samples on lossless formats
223235

224-
if get_ffmpeg_major_version() == 4 and format == "wav":
225-
pytest.skip("Swresample with FFmpeg 4 doesn't work on wav files")
226-
227236
asset = NASA_AUDIO_MP3
228237
source_samples = self.decode(asset).data
229238

@@ -249,7 +258,7 @@ def test_round_trip(self, method, format, tmp_path):
249258
self.decode(encoded_source).data, source_samples, rtol=rtol, atol=atol
250259
)
251260

252-
@pytest.mark.skipif(in_fbcode(), reason="TODO: enable ffmpeg CLI")
261+
@needs_ffmpeg_cli
253262
@pytest.mark.parametrize("asset", (NASA_AUDIO_MP3, SINE_MONO_S32))
254263
@pytest.mark.parametrize("bit_rate", (None, 0, 44_100, 999_999_999))
255264
@pytest.mark.parametrize("num_channels", (None, 1, 2))
@@ -356,17 +365,30 @@ def test_against_cli(
356365
@pytest.mark.parametrize("asset", (NASA_AUDIO_MP3, SINE_MONO_S32))
357366
@pytest.mark.parametrize("bit_rate", (None, 0, 44_100, 999_999_999))
358367
@pytest.mark.parametrize("num_channels", (None, 1, 2))
359-
@pytest.mark.parametrize("format", ("mp3", "wav", "flac"))
368+
@pytest.mark.parametrize(
369+
"format",
370+
[
371+
pytest.param(
372+
"mp3",
373+
marks=pytest.mark.skipif(
374+
IS_WINDOWS and get_ffmpeg_major_version() <= 5,
375+
reason="Encoding mp3 on Windows is weirdly buggy",
376+
),
377+
),
378+
pytest.param(
379+
"wav",
380+
marks=pytest.mark.skipif(
381+
get_ffmpeg_major_version() == 4,
382+
reason="Swresample with FFmpeg 4 doesn't work on wav files",
383+
),
384+
),
385+
"flac",
386+
],
387+
)
360388
@pytest.mark.parametrize("method", ("to_tensor", "to_file_like"))
361389
def test_against_to_file(
362390
self, asset, bit_rate, num_channels, format, tmp_path, method
363391
):
364-
if get_ffmpeg_major_version() == 4 and format == "wav":
365-
pytest.skip("Swresample with FFmpeg 4 doesn't work on wav files")
366-
if IS_WINDOWS and get_ffmpeg_major_version() <= 5 and format == "mp3":
367-
# TODO: https://github.com/pytorch/torchcodec/issues/837
368-
pytest.skip("Encoding mp3 on Windows is weirdly buggy")
369-
370392
encoder = AudioEncoder(self.decode(asset).data, sample_rate=asset.sample_rate)
371393

372394
params = dict(bit_rate=bit_rate, num_channels=num_channels)
@@ -816,16 +838,27 @@ def encode_to_tensor(frames):
816838
)
817839

818840
@pytest.mark.parametrize(
819-
"format", ("mov", "mp4", "mkv", pytest.param("webm", marks=pytest.mark.slow))
841+
"format",
842+
[
843+
"mov",
844+
"mp4",
845+
"mkv",
846+
pytest.param(
847+
"webm",
848+
marks=[
849+
pytest.mark.slow,
850+
pytest.mark.skipif(
851+
get_ffmpeg_major_version() == 4
852+
or (IS_WINDOWS and get_ffmpeg_major_version() in (6, 7)),
853+
reason="Codec for webm is not available in this FFmpeg installation.",
854+
),
855+
],
856+
),
857+
],
820858
)
821859
@pytest.mark.parametrize("method", ("to_file", "to_tensor", "to_file_like"))
822860
def test_round_trip(self, tmp_path, format, method):
823861
# Test that decode(encode(decode(frames))) == decode(frames)
824-
ffmpeg_version = get_ffmpeg_major_version()
825-
if format == "webm" and (
826-
ffmpeg_version == 4 or (IS_WINDOWS and ffmpeg_version in (6, 7))
827-
):
828-
pytest.skip("Codec for webm is not available in this FFmpeg installation.")
829862
source_frames = self.decode(TEST_SRC_2_720P.path).data
830863

831864
# Frame rate is fixed with num frames decoded
@@ -859,25 +892,29 @@ def test_round_trip(self, tmp_path, format, method):
859892

860893
@pytest.mark.parametrize(
861894
"format",
862-
(
895+
[
863896
"mov",
864897
"mp4",
865898
"avi",
866899
"mkv",
867900
"flv",
868901
"gif",
869-
pytest.param("webm", marks=pytest.mark.slow),
870-
),
902+
pytest.param(
903+
"webm",
904+
marks=[
905+
pytest.mark.slow,
906+
pytest.mark.skipif(
907+
get_ffmpeg_major_version() == 4
908+
or (IS_WINDOWS and get_ffmpeg_major_version() in (6, 7)),
909+
reason="Codec for webm is not available in this FFmpeg installation.",
910+
),
911+
],
912+
),
913+
],
871914
)
872915
@pytest.mark.parametrize("method", ("to_tensor", "to_file_like"))
873916
def test_against_to_file(self, tmp_path, format, method):
874917
# Test that to_file, to_tensor, and to_file_like produce the same results
875-
ffmpeg_version = get_ffmpeg_major_version()
876-
if format == "webm" and (
877-
ffmpeg_version == 4 or (IS_WINDOWS and ffmpeg_version in (6, 7))
878-
):
879-
pytest.skip("Codec for webm is not available in this FFmpeg installation.")
880-
881918
source_frames = self.decode(TEST_SRC_2_720P.path).data
882919
encoder = VideoEncoder(frames=source_frames, frame_rate=30)
883920

@@ -898,17 +935,26 @@ def test_against_to_file(self, tmp_path, format, method):
898935
rtol=0,
899936
)
900937

901-
@pytest.mark.skipif(in_fbcode(), reason="ffmpeg CLI not available")
902938
@pytest.mark.parametrize(
903939
"format",
904-
(
940+
[
905941
"mov",
906942
"mp4",
907943
"avi",
908944
"mkv",
909945
"flv",
910-
pytest.param("webm", marks=pytest.mark.slow),
911-
),
946+
pytest.param(
947+
"webm",
948+
marks=[
949+
pytest.mark.slow,
950+
pytest.mark.skipif(
951+
get_ffmpeg_major_version() == 4
952+
or (IS_WINDOWS and get_ffmpeg_major_version() in (6, 7)),
953+
reason="Codec for webm is not available in this FFmpeg installation.",
954+
),
955+
],
956+
),
957+
],
912958
)
913959
@pytest.mark.parametrize(
914960
"encode_params",
@@ -923,12 +969,6 @@ def test_against_to_file(self, tmp_path, format, method):
923969
def test_video_encoder_against_ffmpeg_cli(
924970
self, tmp_path, format, encode_params, method
925971
):
926-
ffmpeg_version = get_ffmpeg_major_version()
927-
if format == "webm" and (
928-
ffmpeg_version == 4 or (IS_WINDOWS and ffmpeg_version in (6, 7))
929-
):
930-
pytest.skip("Codec for webm is not available in this FFmpeg installation.")
931-
932972
pixel_format = encode_params["pixel_format"]
933973
crf = encode_params["crf"]
934974
preset = encode_params["preset"]
@@ -1101,10 +1141,7 @@ def write(self, data):
11011141
):
11021142
encoder.to_file_like(NoSeekMethod(), format="mp4")
11031143

1104-
@pytest.mark.skipif(
1105-
in_fbcode(),
1106-
reason="ffprobe not available internally",
1107-
)
1144+
@needs_ffmpeg_cli
11081145
@pytest.mark.parametrize(
11091146
"format,codec_spec",
11101147
[
@@ -1132,10 +1169,7 @@ def test_codec_parameter_utilized(self, tmp_path, format, codec_spec):
11321169
]
11331170
assert actual_codec_spec == codec_spec
11341171

1135-
@pytest.mark.skipif(
1136-
in_fbcode(),
1137-
reason="ffprobe not available internally",
1138-
)
1172+
@needs_ffmpeg_cli
11391173
@pytest.mark.parametrize(
11401174
"codec_spec,codec_impl",
11411175
[
@@ -1178,7 +1212,7 @@ def test_codec_spec_vs_impl_equivalence(self, tmp_path, codec_spec, codec_impl):
11781212
frames_impl = self.decode(impl_output).data
11791213
torch.testing.assert_close(frames_spec, frames_impl, rtol=0, atol=0)
11801214

1181-
@pytest.mark.skipif(in_fbcode(), reason="ffprobe not available")
1215+
@needs_ffmpeg_cli
11821216
@pytest.mark.parametrize(
11831217
"profile,colorspace,color_range",
11841218
[

test/test_ops.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
from .utils import (
4343
all_supported_devices,
4444
assert_frames_equal,
45-
in_fbcode,
4645
NASA_AUDIO,
4746
NASA_AUDIO_MP3,
4847
NASA_VIDEO,
4948
needs_cuda,
49+
needs_ffmpeg_cli,
5050
SINE_MONO_S32,
5151
SINE_MONO_S32_44100,
5252
SINE_MONO_S32_8000,
@@ -495,10 +495,7 @@ def test_frame_pts_equality(self):
495495
)
496496
assert pts_is_equal
497497

498-
@pytest.mark.skipif(
499-
in_fbcode(),
500-
reason="ffprobe not available internally",
501-
)
498+
@needs_ffmpeg_cli
502499
def test_seek_mode_custom_frame_mappings_fails(self):
503500
with pytest.raises(
504501
RuntimeError,
@@ -539,10 +536,7 @@ def test_seek_mode_custom_frame_mappings_fails(self):
539536
decoder, stream_index=0, custom_frame_mappings=different_lengths
540537
)
541538

542-
@pytest.mark.skipif(
543-
in_fbcode(),
544-
reason="ffprobe not available internally",
545-
)
539+
@needs_ffmpeg_cli
546540
@pytest.mark.parametrize("device", all_supported_devices())
547541
def test_seek_mode_custom_frame_mappings(self, device):
548542
stream_index = 3 # custom_frame_index seek mode requires a stream index

test/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def needs_cuda(test_item):
2727
return pytest.mark.needs_cuda(test_item)
2828

2929

30+
# Decorator for skipping ffmpeg tests when ffmpeg cli isn't available. The tests are
31+
# effectively marked to be skipped in pytest_collection_modifyitems() of
32+
# conftest.py
33+
def needs_ffmpeg_cli(test_item):
34+
return pytest.mark.needs_ffmpeg_cli(test_item)
35+
36+
3037
# This is a special device string that we use to test the "beta" CUDA backend.
3138
# It only exists here, in this test utils file. Public and core APIs have no
3239
# idea that this is how we're tesing them. That is, that's not a supported

0 commit comments

Comments
 (0)