Вот код:
# selects.py
from sqlalchemy import create_engine, Column, Integer, String, Float, ForeignKey, select
from sqlalchemy.orm import declarative_base, relationship, Session
from typing import List, Tuple

Base = declarative_base()

class Album(Base):
    __tablename__ = 'albums'
    AlbumId = Column(Integer, primary_key=True)
    Title = Column(String)
    ArtistId = Column(Integer, ForeignKey('artists.ArtistId'))

    artist = relationship("Artist", back_populates="albums")
    tracks = relationship("Track", back_populates="album")


class Artist(Base):
    __tablename__ = 'artists'
    ArtistId = Column(Integer, primary_key=True)
    Name = Column(String)

    albums = relationship("Album", back_populates="artist")


class Genre(Base):
    __tablename__ = 'genres'
    GenreId = Column(Integer, primary_key=True)
    Name = Column(String)

    tracks = relationship("Track", back_populates="genre")


class MediaType(Base):
    __tablename__ = 'media_types'
    MediaTypeId = Column(Integer, primary_key=True)
    Name = Column(String)

    tracks = relationship("Track", back_populates="media_type")


class Playlist(Base):
    __tablename__ = 'playlists'
    PlaylistId = Column(Integer, primary_key=True)
    Name = Column(String)

    playlist_tracks = relationship("PlaylistTrack", back_populates="playlist")


class PlaylistTrack(Base):
    __tablename__ = 'playlist_track'
    PlaylistId = Column(Integer, ForeignKey('playlists.PlaylistId'), primary_key=True)
    TrackId = Column(Integer, ForeignKey('tracks.TrackId'), primary_key=True)

    playlist = relationship("Playlist", back_populates="playlist_tracks")
    track = relationship("Track", back_populates="playlist_tracks")


class Track(Base):
    __tablename__ = 'tracks'
    TrackId = Column(Integer, primary_key=True)
    Name = Column(String)
    AlbumId = Column(Integer, ForeignKey('albums.AlbumId'))
    MediaTypeId = Column(Integer, ForeignKey('media_types.MediaTypeId'))
    GenreId = Column(Integer, ForeignKey('genres.GenreId'))
    Composer = Column(String)
    Milliseconds = Column(Integer)
    Bytes = Column(Integer)
    UnitPrice = Column(Float)

    album = relationship("Album", back_populates="tracks")
    media_type = relationship("MediaType", back_populates="tracks")
    genre = relationship("Genre", back_populates="tracks")
    playlist_tracks = relationship("PlaylistTrack", back_populates="track")


class DataBaseHandler:
    def __init__(self, db_path: str):
        """
        Инициализирует соединение с базой данных.
        :param db_path: Путь к файлу базы данных Chinook.
        """
        self.engine = create_engine(f"sqlite:///{db_path}")
        Base.metadata.create_all(self.engine)
        self.session = Session(bind=self.engine)

    def teardown(self):
        """
        Закрывает соединение с базой данных.
        """
        self.session.close()
        self.engine.dispose()

    def get_most_expensive_track_names(self, limit: int) -> List[Tuple[str]]:
        """
        Возвращает имена самых дорогих треков.
        :param limit: Количество треков для возврата.
        :return: Список кортежей с именами треков.
        """
        stmt = (
            select(Track.Name)
            .order_by(Track.UnitPrice.desc())
            .limit(limit)
        )
        result = self.session.execute(stmt).all()
        return result

    def get_tracks_of_given_genres(self, genres: List[str], number_of_tracks: int) -> List[Tuple[str]]:
        """
        Возвращает треки, соответствующие заданным жанрам.
        :param genres: Список жанров.
        :param number_of_tracks: Количество треков для возврата.
        :return: Список кортежей с именами треков.
        """
        stmt = (
            select(Track.Name)
            .join(Track.genre)
            .where(Genre.Name.in_(genres))
            .order_by(Track.Name)  # Изменено на сортировку по TrackId
            .limit(number_of_tracks)
        )
        result = self.session.execute(stmt).all()
        return result

    def get_tracks_that_belong_to_playlist_found_by_name(self, name_needle: str) -> List[Tuple[str, str]]:
        """
        Возвращает треки, принадлежащие плейлистам, найденным по имени.
        :param name_needle: Часть имени плейлиста для поиска.
        :return: Список кортежей с именами треков и именами плейлистов.
        """
        like_pattern = f"%{name_needle}%"
        stmt = (
            select(Track.Name, Playlist.Name)
            .join(PlaylistTrack, Track.TrackId == PlaylistTrack.TrackId)
            .join(Playlist, PlaylistTrack.PlaylistId == Playlist.PlaylistId)
            .where(Playlist.Name.like(like_pattern))
            .order_by(Track.TrackId.asc())  # Сортировка по TrackId для консистентности
        )
        result = self.session.execute(stmt).all()
        return result
Должен решать задачу:
selects

Условие

Нужно реализовать класс, который инкапуслирует общение с БД. Потребуется релизовать три метода, которые запрашивают данные из базы В этой задаче необходимо использовать sqlalchemy !!!

Методы init, teardown даны для того, чтобы не приходилось для каждого теста открывать отдельное соединение, а также чтобы в конце закрыть его.

Описание того, что нужно вернуть, указано в докстринге к каждому из методов заглушки. В качестве базы используется тестовая база из туториала по sqlite3. Пдфку с ее схемой можно найти там же где и сам файл или в лекции
НО выдает ошибки:
/usr/bin/python3 /Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm/_jb_pytest_runner.py --path /Users/aleksandrvoytsev/PycharmProjects/hw-6-Kyronison/selects/test_public.py 
Testing started at 16:35 ...
Launching pytest with arguments /Users/aleksandrvoytsev/PycharmProjects/hw-6-Kyronison/selects/test_public.py --no-header --no-summary -q in /Users/aleksandrvoytsev/PycharmProjects/hw-6-Kyronison/selects

============================= test session starts ==============================
collecting ... collected 9 items

test_public.py::test_most_expensive_tracks PASSED                        [ 11%]
test_public.py::test_track_by_type[case0] FAILED                         [ 22%]
test_public.py:85 (test_track_by_type[case0])
[('(Anesthesia) Pulling Teeth',),
 ('(We Are) The Road Crew',),
 ('...And Justice For All',),
 ('13 Years Of Grief',),
 ('14 Years',),
 ('2 Minutes To Midnight',),
 ('2 Minutes To Midnight',),
 ('2 Minutes To Midnight',),
 ('2 Minutes To Midnight',),
 ('2 X 4',)] != [('The Hellion',),
 ('Soldier Side - Intro',),
 ('My World',),
 ('The Awakening',),
 ('Bite The Bullet',),
 ('FX',),
 ('Intro',),
 ("This Cocaine Makes Me Feel Like I'm On This Song",),
 ('Cigaro',),
 ('Stone Cold Crazy',)]

<Click to see difference>

handler = <selects.DataBaseHandler object at 0x1114f7670>
case = TrackByTypes(media_types=['Metal'], results=[('The Hellion',), ('Soldier Side - Intro',), ('My World',), ('The Awakeni...ro',), ("This Cocaine Makes Me Feel Like I'm On This Song",), ('Cigaro',), ('Stone Cold Crazy',)], number_of_tracks=10)

    @pytest.mark.parametrize('case', TrackByGenresCases)
    def test_track_by_type(handler: DataBaseHandler, case: TrackByTypes) -> None:
        result = handler.get_tracks_of_given_genres(case.media_types, case.number_of_tracks)
>       assert result == case.results
E       assert [('(Anesthesia) Pulling Teeth',), ('(We Are) The Road Crew',), ('...And Justice For All',), ('13 Years Of Grief',), ('14 Years',), ('2 Minutes To Midnight',), ('2 Minutes To Midnight',), ('2 Minutes To Midnight',), ('2 Minutes To Midnight',), ('2 X 4',)] == [('The Hellion',), ('Soldier Side - Intro',), ('My World',), ('The Awakening',), ('Bite The Bullet',), ('FX',), ('Intro',), ("This Cocaine Makes Me Feel Like I'm On This Song",), ('Cigaro',), ('Stone Cold Crazy',)]
E         
E         At index 0 diff: ('(Anesthesia) Pulling Teeth',) != ('The Hellion',)
E         
E         Full diff:
E           [
E         +     ('(Anesthesia) Pulling Teeth',),
E         +     ('(We Are) The Road Crew',),
E         +     ('...And Justice For All',),
E         +     ('13 Years Of Grief',),
E         +     ('14 Years',),
E         +     ('2 Minutes To Midnight',),
E         +     ('2 Minutes To Midnight',),
E         +     ('2 Minutes To Midnight',),
E         +     ('2 Minutes To Midnight',),
E         +     ('2 X 4',),
E         -     (
E         -         'The Hellion',
E         -     ),
E         -     (
E         -         'Soldier Side - Intro',
E         -     ),
E         -     (
E         -         'My World',
E         -     ),
E         -     (
E         -         'The Awakening',
E         -     ),
E         -     (
E         -         'Bite The Bullet',
E         -     ),
E         -     (
E         -         'FX',
E         -     ),
E         -     (
E         -         'Intro',
E         -     ),
E         -     (
E         -         "This Cocaine Makes Me Feel Like I'm On This Song",
E         -     ),
E         -     (
E         -         'Cigaro',
E         -     ),
E         -     (
E         -         'Stone Cold Crazy',
E         -     ),
E           ]

test_public.py:89: AssertionError

test_public.py::test_track_by_type[case1] FAILED                         [ 33%]
test_public.py:85 (test_track_by_type[case1])
[("(I Can't Help) Falling In Love With You",),
 ('01 - Prowler',),
 ('02 - Sanctuary',),
 ('03 - Remember Tomorrow',),
 ('04 - Running Free',),
 ('05 - Phantom of the Opera',),
 ('06 - Transylvania',),
 ('07 - Strange World',),
 ('08 - Charlotte the Harlot',),
 ('09 - Iron Maiden',),
 ('A Cor Do Sol',),
 ('A Cor Do Sol',),
 ('A Estrada',),
 ('A Estrada',),
 ('A Sombra Da Maldade',)] != [('Too Many Ways (Alternate)',),
 ('She Suits Me To A Tee',),
 ('First Time I Met The Blues',),
 ('Travis Walk',),
 ("The House Is Rockin'",),
 ('Scratch-N-Sniff',),
 ('Badge',),
 ('Let Me Love You Baby',),
 ('Keep It To Myself (Aka Keep It To Yourself)',),
 ('Strange Brew',),
 ('Pensamento',),
 ('I Feel Free',),
 ('Let Me Love You Baby',),
 ('Doutor',),
 ('Promises',)]

<Click to see difference>

handler = <selects.DataBaseHandler object at 0x1114f7670>
case = TrackByTypes(media_types=['Reggae', 'Blues'], results=[('Too Many Ways (Alternate)',), ('She Suits Me To A Tee',), ('F...rew',), ('Pensamento',), ('I Feel Free',), ('Let Me Love You Baby',), ('Doutor',), ('Promises',)], number_of_tracks=15)

    @pytest.mark.parametrize('case', TrackByGenresCases)
    def test_track_by_type(handler: DataBaseHandler, case: TrackByTypes) -> None:
        result = handler.get_tracks_of_given_genres(case.media_types, case.number_of_tracks)
>       assert result == case.results
E       assert [("(I Can't Help) Falling In Love With You",), ('01 - Prowler',), ('02 - Sanctuary',), ('03 - Remember Tomorrow',), ('04 - Running Free',), ('05 - Phantom of the Opera',), ('06 - Transylvania',), ('07 - Strange World',), ('08 - Charlotte the Harlot',), ('09 - Iron Maiden',), ('A Cor Do Sol',), ('A Cor Do Sol',), ('A Estrada',), ('A Estrada',), ('A Sombra Da Maldade',)] == [('Too Many Ways (Alternate)',), ('She Suits Me To A Tee',), ('First Time I Met The Blues',), ('Travis Walk',), ("The House Is Rockin'",), ('Scratch-N-Sniff',), ('Badge',), ('Let Me Love You Baby',), ('Keep It To Myself (Aka Keep It To Yourself)',), ('Strange Brew',), ('Pensamento',), ('I Feel Free',), ('Let Me Love You Baby',), ('Doutor',), ('Promises',)]
E         
E         At index 0 diff: ("(I Can't Help) Falling In Love With You",) != ('Too Many Ways (Alternate)',)
E         
E         Full diff:
E           [
E         +     ("(I Can't Help) Falling In Love With You",),
E         +     ('01 - Prowler',),
E         +     ('02 - Sanctuary',),
E         +     ('03 - Remember Tomorrow',),
E         +     ('04 - Running Free',),
E         +     ('05 - Phantom of the Opera',),
E         +     ('06 - Transylvania',),
E         +     ('07 - Strange World',),
E         +     ('08 - Charlotte the Harlot',),
E         +     ('09 - Iron Maiden',),
E         +     ('A Cor Do Sol',),
E         +     ('A Cor Do Sol',),
E         +     ('A Estrada',),
E         +     ('A Estrada',),
E         +     ('A Sombra Da Maldade',),
E         -     (
E         -         'Too Many Ways (Alternate)',
E         -     ),
E         -     (
E         -         'She Suits Me To A Tee',
E         -     ),
E         -     (
E         -         'First Time I Met The Blues',
E         -     ),
E         -     (
E         -         'Travis Walk',
E         -     ),
E         -     (
E         -         "The House Is Rockin'",
E         -     ),
E         -     (
E         -         'Scratch-N-Sniff',
E         -     ),
E         -     (
E         -         'Badge',
E         -     ),
E         -     (
E         -         'Let Me Love You Baby',
E         -     ),
E         -     (
E         -         'Keep It To Myself (Aka Keep It To Yourself)',
E         -     ),
E         -     (
E         -         'Strange Brew',
E         -     ),
E         -     (
E         -         'Pensamento',
E         -     ),
E         -     (
E         -         'I Feel Free',
E         -     ),
E         -     (
E         -         'Let Me Love You Baby',
E         -     ),
E         -     (
E         -         'Doutor',
E         -     ),
E         -     (
E         -         'Promises',
E         -     ),
E           ]

test_public.py:89: AssertionError

test_public.py::test_track_by_type[case2] FAILED                         [ 44%]
test_public.py:85 (test_track_by_type[case2])
[('A Benihana Christmas, Pts. 1 & 2',),
 ('Back from Vacation',),
 ('Beach Games',),
 ('Ben Franklin',),
 ('Branch Closing',),
 ('Business School',),
 ('Cocktails',),
 ("Phyllis's Wedding",),
 ("Producer's Cut: The Return",),
 ('Product Recall',),
 ('Safety Training',),
 ('The Convict',),
 ('The Job',),
 ('The Negotiation',),
 ('The Return',),
 ('Traveling Salesmen',),
 ("Women's Appreciation",)] != [('Product Recall',),
 ('Safety Training',),
 ("Phyllis's Wedding",),
 ('Back from Vacation',),
 ('Ben Franklin',),
 ('Cocktails',),
 ('The Convict',),
 ('Traveling Salesmen',),
 ('Business School',),
 ('Beach Games',),
 ("Producer's Cut: The Return",),
 ('The Return',),
 ("Women's Appreciation",),
 ('The Negotiation',),
 ('Branch Closing',),
 ('A Benihana Christmas, Pts. 1 & 2',),
 ('The Job',)]

<Click to see difference>

handler = <selects.DataBaseHandler object at 0x1114f7670>
case = TrackByTypes(media_types=['Comedy', 'Comedy'], results=[('Product Recall',), ('Safety Training',), ("Phyllis's Wedding..., ('The Negotiation',), ('Branch Closing',), ('A Benihana Christmas, Pts. 1 & 2',), ('The Job',)], number_of_tracks=25)

    @pytest.mark.parametrize('case', TrackByGenresCases)
    def test_track_by_type(handler: DataBaseHandler, case: TrackByTypes) -> None:
        result = handler.get_tracks_of_given_genres(case.media_types, case.number_of_tracks)
>       assert result == case.results
E       assert [('A Benihana Christmas, Pts. 1 & 2',), ('Back from Vacation',), ('Beach Games',), ('Ben Franklin',), ('Branch Closing',), ('Business School',), ('Cocktails',), ("Phyllis's Wedding",), ("Producer's Cut: The Return",), ('Product Recall',), ('Safety Training',), ('The Convict',), ('The Job',), ('The Negotiation',), ('The Return',), ('Traveling Salesmen',), ("Women's Appreciation",)] == [('Product Recall',), ('Safety Training',), ("Phyllis's Wedding",), ('Back from Vacation',), ('Ben Franklin',), ('Cocktails',), ('The Convict',), ('Traveling Salesmen',), ('Business School',), ('Beach Games',), ("Producer's Cut: The Return",), ('The Return',), ("Women's Appreciation",), ('The Negotiation',), ('Branch Closing',), ('A Benihana Christmas, Pts. 1 & 2',), ('The Job',)]
E         
E         At index 0 diff: ('A Benihana Christmas, Pts. 1 & 2',) != ('Product Recall',)
E         
E         Full diff:
E           [
E         -     (
E         -         'Product Recall',
E         -     ),
E         -     (
E         -         'Safety Training',
E         -     ),
E         -     (
E         -         "Phyllis's Wedding",
E         -     ),
E         -     (
E         -         'Back from Vacation',
E         -     ),
E         -     (
E         -         'Ben Franklin',
E         -     ),
E         -     (
E         -         'Cocktails',
E         -     ),
E         -     (
E         -         'The Convict',
E         -     ),
E         -     (
E         -         'Traveling Salesmen',
E         -     ),
E         -     (
E         -         'Business School',
E         -     ),
E         -     (
E         -         'Beach Games',
E         -     ),
E         -     (
E         -         "Producer's Cut: The Return",
E         -     ),
E         -     (
E         -         'The Return',
E         -     ),
E         -     (
E         -         "Women's Appreciation",
E         -     ),
E         -     (
E         -         'The Negotiation',
E         -     ),
E         -     (
E         -         'Branch Closing',
E         -     ),
E         -     (
E         -         'A Benihana Christmas, Pts. 1 & 2',
E         ?     ^^^^
E         +     ('A Benihana Christmas, Pts. 1 & 2',),
E         ?     ^                                   ++
E         -     ),
E         -     (
E         +     ('Back from Vacation',),
E         +     ('Beach Games',),
E         +     ('Ben Franklin',),
E         +     ('Branch Closing',),
E         +     ('Business School',),
E         +     ('Cocktails',),
E         +     ("Phyllis's Wedding",),
E         +     ("Producer's Cut: The Return",),
E         +     ('Product Recall',),
E         +     ('Safety Training',),
E         +     ('The Convict',),
E         -         'The Job',
E         ?     ^^^^
E         +     ('The Job',),
E         ?     ^          ++
E         -     ),
E         +     ('The Negotiation',),
E         +     ('The Return',),
E         +     ('Traveling Salesmen',),
E         +     ("Women's Appreciation",),
E           ]

test_public.py:89: AssertionError

test_public.py::test_track_by_type[case3] PASSED                         [ 55%]
test_public.py::test_track_by_playlist_name[case0] PASSED                [ 66%]
test_public.py::test_track_by_playlist_name[case1] PASSED                [ 77%]
test_public.py::test_track_by_playlist_name[case2] PASSED                [ 88%]
test_public.py::test_track_by_playlist_name[case3] PASSED                [100%]

========================= 3 failed, 6 passed in 0.21s ==========================

Process finished with exit code 1