-
Notifications
You must be signed in to change notification settings - Fork 55
Fixtures test3 edit1 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fixtures test3 edit1 #15
Conversation
| import pytest | ||
|
|
||
| # ВОПРОС: то есть в этом тесте можно было обойтись совсем-совсем без фикстур? | ||
| # Они получились очень мелкими и многочисленными |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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'), | ||
| ] |
There was a problem hiding this comment.
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() | ||
|
|
||
| # Вопрос: убрать что ли нафиг этот тест, тк с такими данными результат - не тайпэррор( |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ответ на этот вопрос ты уже знаешь, значения фикстур динамически можно получать через служебную фикстуру request.
Но в данном случае эти фикстуры вообще не нужны – они не несут понятной нагрузки, не универсальны и всё такое.
No description provided.