Skip to content

Sprint_2#5

Open
MixaTorres7 wants to merge 2 commits intomainfrom
develop
Open

Sprint_2#5
MixaTorres7 wants to merge 2 commits intomainfrom
develop

Conversation

@MixaTorres7
Copy link
Owner

No description provided.

tests.py Outdated
assert len(collector.get_books_genre()) == 2

# Тест для add_new_book - добавление книги с валидным названием
def test_add_new_book_valid_name_book_added(self):

Choose a reason for hiding this comment

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

Нужно исправить: по названию тест не отличается от предыдущего. В нем название тоже валидное

tests.py Outdated
class TestBooksCollector:

def test_add_new_book_add_two_books(self):
collector = BooksCollector()

Choose a reason for hiding this comment

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

Можно улучшить: предусловие, общее для всех тестов, лучше вынести в фикстуру

tests.py Outdated
collector = BooksCollector()
collector.add_new_book('Метро 2033')
collector.set_book_genre('Метро 2033', 'Фантастика')
assert collector.get_book_genre('Метро 2033') == 'Фантастика'

Choose a reason for hiding this comment

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

Нужно исправить: для get_book_genre должен быть отдельный тест. Тесты не должны дублировать друг друга. В идеале - чтобы в каждом тесте использовался только один проверяемый метод, все остальное можно получить прямым доступом к словарям и спискам

collector.set_book_genre('Книга 1', 'Ужасы')
collector.set_book_genre('Книга 2', 'Ужасы')

result = collector.get_books_with_specific_genre('Ужасы')

Choose a reason for hiding this comment

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

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

tests.py Outdated
collector.set_book_genre('Книга 2', 'Ужасы')

result = collector.get_books_with_specific_genre('Ужасы')
assert 'Книга 1' in result

Choose a reason for hiding this comment

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

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

collector.add_new_book('Что делать, если ваш кот хочет вас убить')
assert len(collector.get_books_genre()) == 2
# Фикстура для создания экземпляра коллектора перед каждым тестом
@pytest.fixture
Copy link

Choose a reason for hiding this comment

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

Можно улучшить: фикстуру лучше хранить в отдельном модуле

}

children_books = collector.get_books_for_children()
assert 'Детская книга' in children_books
Copy link

Choose a reason for hiding this comment

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

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

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