Вот код:
# 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(Genre, Track.GenreId == Genre.GenreId)
            .where(Genre.Name.in_(genres))
            .order_by(Track.Name)  # Убедитесь, что сортировка соответствует ожидаемому порядку
            .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())  # Сортировка для консистентности
        )
        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:23 ...
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])
[('Enter Sandman',),
 ('Master Of Puppets',),
 ('Harvester Of Sorrow',),
 ('The Unforgiven',),
 ('Sad But True',),
 ('Creeping Death',),
 ('Wherever I May Roam',),
 ('Welcome Home (Sanitarium)',),
 ('Intro/ Low Down',),
 ('13 Years Of Grief',)] != [('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 0x1036e7ee0>
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 [('Enter Sandman',), ('Master Of Puppets',), ('Harvester Of Sorrow',), ('The Unforgiven',), ('Sad But True',), ('Creeping Death',), ('Wherever I May Roam',), ('Welcome Home (Sanitarium)',), ('Intro/ Low Down',), ('13 Years Of Grief',)] == [('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: ('Enter Sandman',) != ('The Hellion',)
E         
E         Full diff:
E           [
E         +     ('Enter Sandman',),
E         +     ('Master Of Puppets',),
E         +     ('Harvester Of Sorrow',),
E         +     ('The Unforgiven',),
E         +     ('Sad But True',),
E         +     ('Creeping Death',),
E         +     ('Wherever I May Roam',),
E         +     ('Welcome Home (Sanitarium)',),
E         +     ('Intro/ Low Down',),
E         +     ('13 Years Of Grief',),
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])
[('First Time I Met The Blues',),
 ('Let Me Love You Baby',),
 ('Stone Crazy',),
 ('Pretty Baby',),
 ('When My Left Eye Jumps',),
 ('Leave My Girl Alone',),
 ('She Suits Me To A Tee',),
 ('Keep It To Myself (Aka Keep It To Yourself)',),
 ('My Time After Awhile',),
 ('Too Many Ways (Alternate)',),
 ("Talkin' 'Bout Women Obviously",),
 ('Layla',),
 ('Badge',),
 ('I Feel Free',),
 ('Sunshine Of Your Love',)] != [('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 0x1036e7ee0>
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 [('First Time I Met The Blues',), ('Let Me Love You Baby',), ('Stone Crazy',), ('Pretty Baby',), ('When My Left Eye Jumps',), ('Leave My Girl Alone',), ('She Suits Me To A Tee',), ('Keep It To Myself (Aka Keep It To Yourself)',), ('My Time After Awhile',), ('Too Many Ways (Alternate)',), ("Talkin' 'Bout Women Obviously",), ('Layla',), ('Badge',), ('I Feel Free',), ('Sunshine Of Your Love',)] == [('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: ('First Time I Met The Blues',) != ('Too Many Ways (Alternate)',)
E         
E         Full diff:
E           [
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         +     ('First Time I Met The Blues',),
E         ?     ^                             ++
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         +     ('Let Me Love You Baby',),
E         ?     ^                       ++
E         -     ),
E         -     (
E         +     ('Stone Crazy',),
E         +     ('Pretty Baby',),
E         +     ('When My Left Eye Jumps',),
E         +     ('Leave My Girl Alone',),
E         +     ('She Suits Me To A Tee',),
E         -         'Keep It To Myself (Aka Keep It To Yourself)',
E         ?     ^^^^
E         +     ('Keep It To Myself (Aka Keep It To Yourself)',),
E         ?     ^                                              ++
E         +     ('My Time After Awhile',),
E         +     ('Too Many Ways (Alternate)',),
E         +     ("Talkin' 'Bout Women Obviously",),
E         +     ('Layla',),
E         +     ('Badge',),
E         -     ),
E         -     (
E         -         'Strange Brew',
E         -     ),
E         -     (
E         -         'Pensamento',
E         -     ),
E         -     (
E         -         'I Feel Free',
E         ?     ^^^^
E         +     ('I Feel Free',),
E         ?     ^              ++
E         +     ('Sunshine Of Your Love',),
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])
[('The Convict',),
 ('A Benihana Christmas, Pts. 1 & 2',),
 ('Back from Vacation',),
 ('Traveling Salesmen',),
 ("Producer's Cut: The Return",),
 ('Ben Franklin',),
 ("Phyllis's Wedding",),
 ('Business School',),
 ('Cocktails',),
 ('The Negotiation',),
 ('Safety Training',),
 ('Product Recall',),
 ("Women's Appreciation",),
 ('Beach Games',),
 ('The Job',),
 ('Branch Closing',),
 ('The Return',)] != [('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 0x1036e7ee0>
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 [('The Convict',), ('A Benihana Christmas, Pts. 1 & 2',), ('Back from Vacation',), ('Traveling Salesmen',), ("Producer's Cut: The Return",), ('Ben Franklin',), ("Phyllis's Wedding",), ('Business School',), ('Cocktails',), ('The Negotiation',), ('Safety Training',), ('Product Recall',), ("Women's Appreciation",), ('Beach Games',), ('The Job',), ('Branch Closing',), ('The Return',)] == [('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: ('The Convict',) != ('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         +     ('The Convict',),
E         ?     ^              ++
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         +     ('Traveling Salesmen',),
E         +     ("Producer's Cut: The Return",),
E         +     ('Ben Franklin',),
E         +     ("Phyllis's Wedding",),
E         +     ('Business School',),
E         +     ('Cocktails',),
E         +     ('The Negotiation',),
E         +     ('Safety Training',),
E         +     ('Product Recall',),
E         +     ("Women's Appreciation",),
E         +     ('Beach Games',),
E         -         'The Job',
E         ?     ^^^^
E         +     ('The Job',),
E         ?     ^          ++
E         -     ),
E         +     ('Branch Closing',),
E         +     ('The Return',),
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.22s ==========================

Process finished with exit code 1

Вот описание БД:
SQLITE
TUTORIAL
media_types
MediaTypeld: INTEGER
Name: NVARCHAR(120)
genres
Genreld: INTEGER
Name: NVARCHAR(120)
playlists
Playlistid: INTEGER
Name: NVARCHAR{120)
playlist track
Playlistid: INTEGER
Trackid: INTEGER
tracks
Trackid: INTEGER
Name: NVARCHAR(200)
Albumid: INTEGER
MediaTypeld: INTEGER
Genreld: INTEGER
Composer: NVARCHAR(220)
Milliseconds: INTEGER
Bytes: INTEGER
UnitPrice: NUMERIC
artists
Artistid: INTEGER
Name: NVARCHAR(120)
invoices
Invoiceld: INTEGER
Customerid INTEGER
InvoiceDate: DATETIME
Billing Address: NVAR...
BillingCity: NVARCHA.
4 more columns...
invoice items
Invoiceltemid: INTEGER
Invoiceld: INTEGER
Trackid INTEGER
UnitPrice: NUMERIC
Quantity: INTEGER
albums
Albumid: INTEGER
Title: NVARCHAR(160)
Artistid: INTEGER
customers
Customerid: INTEGER
FirstName: NVARCHAR(40)
LastName: NVARCHAR(20)
Company: NVARCHAR(B0)
Address: NVARCHAR(70)
City: NVARCHAR(40)
State: NVARCHAR(40)
Country: NVARCHAR(40)
PostalCode: NVARCHAR(10)
Phone: NVARCHAR(24)
Fax: NVARCHAR(24)
Email: NVARCHAR(60)
SupportRepid: INTEGER
employees
Employeeld: INTEGER
LastName: NVARCHAR(20)
FirstName: NVARCHAR(20)
Title: NVARCHAR(30)
ReportsTo: INTEGER
BirthDate: DATETIME
HireDate: DATETIME
Address: NVARCHAR(70)
7 more columns..