Skip to content

Conversation

@DianaRatnikova
Copy link

No description provided.

import pytest

# ВОПРОС: то есть в этом тесте можно было обойтись совсем-совсем без фикстур?
# Они получились очень мелкими и многочисленными
Copy link
Contributor

Choose a reason for hiding this comment

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

Да! Можно :)

# Входное значение для функции
cards = [bank_card1, bank_card2]

expense_result=Expense(amount = decimal.Decimal('112.3'), card = BankCard(last_digits ='4234', owner ='User2'), spent_in = 'Shop_name', spent_at = datetime.datetime(2023, 5, 13, 17, 23))
Copy link
Contributor

Choose a reason for hiding this comment

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

Длинная строка, я бы отформатировал


def test_genderalize():
pass
@pytest.fixture
Copy link
Contributor

Choose a reason for hiding this comment

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

Эти фикстуры тоже едва ли тебе пригодятся где-то ещё.

Ну и не забывай, что место фикстур в конфтесте, а не в файле с тестами

('host_name_2', 'relative_url', 'get_params_mappings_k_and_v', 'url_k_and_v'),
('host_name_1', 'relative_url', 'get_params_mappings_k', 'url_k'),
('host_name_1', 'relative_url', 'get_params_no_querypart', 'url_no_querypart'),
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Тут во-первых не хватает отступа, а во-вторых тут хорошо видно, что ты используешь те же константы, только проксируешь их через фикстуры.

Прикол в том, что фикстуры нужны для универсальных штук, а тут у тебя штуки, которые будут нужны для тестирования только этой функции. Поэтому в фикстуры их выносить смысла не имеет.

with pytest.raises(TypeError):
build_url()

# Вопрос: убрать что ли нафиг этот тест, тк с такими данными результат - не тайпэррор(
Copy link
Contributor

Choose a reason for hiding this comment

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

Дык и до этого тайпэррор был не из-за функции, а из-за данных. Получается, что это ошибка в дизайне теста: ты думала, что будешь тестировать какой-то кейс поведения функции, а оказалось, что этого кейса нет.

return datetime.datetime(datetime.date.today().year,
datetime.date.today().month,
datetime.date.today().day,
hour_str, minute_str)
Copy link
Contributor

Choose a reason for hiding this comment

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

Все многострочные штуки я предпочитаю форматировать вот так:

return datetime.datetime(
    datetime.date.today().year,
    datetime.date.today().month,
    datetime.date.today().day, 
    hour_str,
    minute_str,
)

@pytest.mark.parametrize(
"date_str, time_str, expected_result",
[
# ("2023,12,15", time_str, expected_result),
Copy link
Contributor

Choose a reason for hiding this comment

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

Удоли :)

# ]
#)
#def test__delete_remove_brackets_quotes__is_valid(name, expected_result):
# assert delete_remove_brackets_quotes(name) == expected_result No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Ответ на этот вопрос ты уже знаешь, значения фикстур динамически можно получать через служебную фикстуру request.

Но в данном случае эти фикстуры вообще не нужны – они не несут понятной нагрузки, не универсальны и всё такое.

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