Repository: yt-dlp/yt-dlp
File: test/test_download.py (Python)

Code before:
                    # Check if the exception is not a network related one
                    if not isinstance(err.exc_info[1], (TransportError, UnavailableVideoError)) or (isinstance(err.exc_info[1], HTTPError) and err.exc_info[1].status == 503):
                        if match_exception(err):
                            return
                        err.msg = f'{getattr(err, "msg", err)} ({tname})'
                        raise

                    if try_num == RETRIES:
                        raise

                    print(f'Retrying: {try_num} failed tries\n\n##########\n\n')

                    try_num += 1
                except YoutubeDLError as err:
                    if match_exception(err):
                        return
                    raise
                else:
                    break

            if is_playlist:
                self.assertTrue(res_dict['_type'] in ['playlist', 'multi_video'])
                self.assertTrue('entries' in res_dict)
                expect_info_dict(self, res_dict, test_case.get('info_dict', {}))

            num_entries = len(res_dict['entries'])
            if 'playlist_mincount' in test_case:
                assertGreaterEqual(
                    self, num_entries, test_case['playlist_mincount'],
                    f'Expected at least {test_case["playlist_mincount"]} entries '
                    f'in playlist {test_case["url"]}, but got only {num_entries}')
            if 'playlist_count' in test_case:
                got_text = num_entries if num_entries <= test_case['playlist_count'] else 'more'
                self.assertEqual(
                    num_entries, test_case['playlist_count'],
                    f'Expected exactly {test_case["playlist_count"]} entries '
                    f'in playlist {test_case["url"]}, but got {got_text}')
            if 'playlist_maxcount' in test_case:
                assertLessEqual(
                    self, num_entries, test_case['playlist_maxcount'],
                    f'Expected at most {test_case["playlist_maxcount"]} entries '
                    f'in playlist {test_case["url"]}, but got more')

            # Generalize both playlists and single videos to unified format for
            # simplicity
            if 'entries' not in res_dict:
                res_dict['entries'] = [res_dict]

            for tc_num, tc in enumerate(test_cases):
                tc_res_dict = res_dict['entries'][tc_num]
                # First, check test cases' data against extracted data alone

Review comment (suggestion):
```suggestion
            num_entries = len(res_dict.get('entries', []))
```

Code after:
                        force_generic_extractor=params.get('force_generic_extractor', False))
                except (DownloadError, ExtractorError) as err:
                    # Check if the exception is not a network related one
                    if not isinstance(err.exc_info[1], (TransportError, UnavailableVideoError)) or (isinstance(err.exc_info[1], HTTPError) and err.exc_info[1].status == 503):
                        if match_exception(err):
                            return
                        err.msg = f'{getattr(err, "msg", err)} ({tname})'
                        raise

                    if try_num == RETRIES:
                        raise

                    print(f'Retrying: {try_num} failed tries\n\n##########\n\n')

                    try_num += 1
                except YoutubeDLError as err:
                    if match_exception(err):
                        return
                    raise
                else:
                    break

            if is_playlist:
                self.assertTrue(res_dict['_type'] in ['playlist', 'multi_video'])
                self.assertTrue('entries' in res_dict)
                expect_info_dict(self, res_dict, test_case.get('info_dict', {}))

            num_entries = len(res_dict.get('entries', []))
            if 'playlist_mincount' in test_case:
                mincount = test_case['playlist_mincount']
                assertGreaterEqual(
                    self, num_entries, mincount,
                    f'Expected at least {mincount} entries in playlist {test_url}, but got only {num_entries}')
            if 'playlist_count' in test_case:
                count = test_case['playlist_count']
                got = num_entries if num_entries <= count else 'more'
                self.assertEqual(
                    num_entries, count,
                    f'Expected exactly {count} entries in playlist {test_url}, but got {got}')
            if 'playlist_maxcount' in test_case:
                maxcount = test_case['playlist_maxcount']
                assertLessEqual(
                    self, num_entries, maxcount,
                    f'Expected at most {maxcount} entries in playlist {test_url}, but got more')
            if 'playlist_duration_sum' in test_case:
                got_duration = sum(e['duration'] for e in res_dict['entries'])
                self.assertEqual(
                    test_case['playlist_duration_sum'], got_duration)

            # Generalize both playlists and single videos to unified format for
            # simplicity