Skip to content

Sprint_4#8

Open
AFK-ru wants to merge 3 commits into
mainfrom
develop
Open

Sprint_4#8
AFK-ru wants to merge 3 commits into
mainfrom
develop

Conversation

@AFK-ru
Copy link
Copy Markdown
Owner

@AFK-ru AFK-ru commented Mar 31, 2026

add 9 tests for BooksCollector

Comment thread tests.py

# напиши свои тесты ниже
# чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В тесте есть ошибка. Если ты оставляешь этот тест, ее нужно исправить

Comment thread tests.py
# чтобы тесты были независимыми в каждом из них создавай отдельный экземпляр класса BooksCollector() No newline at end of file

@pytest.fixture
def collector_with_books(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: фикстуры нужны для хранения логики предусловий, а не создания и возвращения данных. Нужные для конкретного еста данные ты можешь задать прямо в нем, напрямую обращаясь к словарю или списку

Comment thread tests.py
assert collector.get_book_genre('Книга 1') == 'Фантастика'


def test_get_book_genre_existing_book(self, collector_with_books):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: тест аналогичен тесту set_book_genre. Попробуй установить значение жанра иначе, или иначе получить его для сравнения. Используй доступ к словарю

Comment thread tests.py Outdated
collector.set_book_genre('Книга 2', 'Комедии')
collector.set_book_genre('Книга 3', 'Детективы')
result = collector.get_books_for_children()
assert 'Книга 1' in result
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно улучшить: состояние списка можно проверить одним ассертом

Comment thread tests.py
assert 'Книга 3' not in favorites


def test_get_list_of_favorites_books_returns_list_with_two_books(self, collector_with_books):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: по сути тест не отличается от добавление в избранное. Проверь методы независимо

Comment thread tests.py
collector = collector_with_books
collector.set_book_genre('Книга 2', 'Комедии')
assert collector.get_book_genre('Книга 2') == 'Комедии'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить: по названию ты проверяешь get_book_genre, но этот метод отсутствует в тесте. Тест подойдет для set метода, названия должны соответствовать сути

Comment thread tests.py Outdated
def test_get_books_genre_returns_dictionary_sum_3(self, collector_with_books):
collector = collector_with_books

books = ['Книга 1', 'Книга 2', 'Книга 3']
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно улучшить: не обязательно каждый раз добавлять книги в словарь через add, значение словаря можно установить напрямую

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants