{"record":{"id":"c07493252d09f68f","repo":"ytdl-org/youtube-dl","slug":"test-case-d-not-found-got-only-d-tests","errorCode":null,"errorMessage":"Test case %d not found, got only %d tests","messagePattern":"Test case (.+?) not found, got only (.+?) tests","errorType":"exception","errorClass":"ExtractorError","httpStatus":null,"severity":"warning","filePath":"youtube_dl/extractor/testurl.py","lineNumber":57,"sourceCode":"                    ('Found multiple matching extractors: %s' %\n                        ' '.join(ie.IE_NAME for ie in matching_extractors)),\n                    expected=True)\n        else:\n            extractor = matching_extractors[0]\n\n        num_str = mobj.group('num')\n        num = int(num_str) if num_str else 0\n\n        testcases = []\n        t = getattr(extractor, '_TEST', None)\n        if t:\n            testcases.append(t)\n        testcases.extend(getattr(extractor, '_TESTS', []))\n\n        try:\n            tc = testcases[num]\n        except IndexError:\n            raise ExtractorError(\n                ('Test case %d not found, got only %d tests' %\n                    (num, len(testcases))),\n                expected=True)\n\n        self.to_screen('Test URL: %s' % tc['url'])\n\n        return self.url_result(tc['url'], video_id=video_id)\n","sourceCodeStart":39,"sourceCodeEnd":65,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/extractor/testurl.py#L39-L65","documentation":"Raised by the testurl extractor when the optional /<num> index in testurl:<extractor>/<num> is out of range: after collecting the extractor's _TEST (singular) plus all _TESTS entries, testcases[num] raised IndexError. The error reports the requested index and how many tests actually exist. Marked expected=True.","triggerScenarios":"A URL like testurl:youtube/99 when the matched extractor has fewer than 100 test cases; note indices are 0-based, so testurl:<name>/<N> fails once N >= number of tests (num defaults to 0 when omitted).","commonSituations":"Off-by-one confusion (asking for test 5 on an extractor with 5 tests — valid indices are 0..4); hard-coded test indices in scripts that break when an extractor's _TESTS list shrinks in a new release.","solutions":["Use a smaller index: the message states 'got only %d tests', so valid indices are 0..that-1.","Omit the index entirely (testurl:<name>) to get the extractor's primary test case.","Regenerate any hard-coded indices after upgrading youtube-dl, since test lists change between versions."],"exampleFix":"# before (5 tests => indices 0..4)\n# youtube-dl testurl:someextractor/5\n# after\n# youtube-dl testurl:someextractor/4   # or simply:\n# youtube-dl testurl:someextractor","handlingStrategy":"validation","validationCode":"# Determine how many tests an extractor exposes before choosing an index\nie = next(e for e in gen_extractors() if e.IE_NAME.lower() == name.lower())\ncount = (1 if getattr(ie, '_TEST', None) else 0) + len(getattr(ie, '_TESTS', []))\nif not 0 <= num < count:\n    print('index %d out of range; valid: 0..%d' % (num, count - 1))","typeGuard":"def valid_test_index(ie, num):\n    \"\"\"True when num indexes into the extractor's collected test cases.\"\"\"\n    total = (1 if getattr(ie, '_TEST', None) else 0) + len(getattr(ie, '_TESTS', []))\n    return isinstance(num, int) and 0 <= num < total","tryCatchPattern":"try:\n    ydl.extract_info('testurl:%s/%d' % (name, num))\nexcept ExtractorError as e:\n    if e.expected and 'not found, got only' in str(e):\n        num = 0  # fall back to the primary test case\n        ydl.extract_info('testurl:%s' % name)\n    else:\n        raise","preventionTips":["Indices are 0-based; with N tests the max valid index is N-1.","Omit the index to always get the extractor's primary test case.","Recompute hard-coded indices after every youtube-dl upgrade."],"tags":["test-utility","user-input","index-error","expected-error"],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}