Skip to content

Feature/do next stage of tests#3

Merged
Beloded1 merged 3 commits intomainfrom
feature/do_next_stage_of_tests
Jun 13, 2023
Merged

Feature/do next stage of tests#3
Beloded1 merged 3 commits intomainfrom
feature/do_next_stage_of_tests

Conversation

@Beloded1
Copy link
Copy Markdown
Owner

@Beloded1 Beloded1 commented Jun 6, 2023

Сделал тесты level_1_7. Сломал голову на four_fraud.py. Нашел явную ошибку в функции, исправил. Но все равно тесты на нее работают некорректно. Думаю функция не возвращает нужный нам список. Могу ошибаться. По остальным думаю все ок.

Copy link
Copy Markdown

@vppuzakov vppuzakov left a comment

Choose a reason for hiding this comment

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

👍 Большой вышел ПР, далеко продвинулись в целом и parametrize написан и фикстуры уже появились - поэтому давай смержим.

А уже в следующих ПР давай поработаем над комментами.

В основном по комментам:

  • параметрайз применять только там, где поведение тестируемое одно, но хочется докидать еще несколько входных параметров для уверенности
  • во всех тестах с expenses очень трудно разобраться без использования фикстуры-фабрики make_expense - сделай ее первым делом - пойдет полегче. Это касается и тех тестов, где expense в параметрайз и тех где в теле теста.
  • тестируемое поведение всегда отражай в названии теста
  • не увлекайся с аннотациями типов в тестах - редко несут пользу

Comment thread coverage.xml


def test__solve_square_equation__if_square_coefficient_is_equal_to_zero():
def test__solve_square_equation__return_one_root_if_square_coefficient_is_equal_to_zero():
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 хорошо, что сохранил старый вариант тестов без параметрайза и полностью с параметрайзом.

Хотя тут можно попробовать найти золотую середину, когда хорошо иметь и отдельные тесты на разные поведения, а когда в рамках теста одного поведения мы хотим проверить несколько кейсов - на нескольких входных параметрах, используя parametrize

Comment thread tests/level_1_5/test_two_square_equation.py
Comment thread tests/level_1_5/test_three_first.py
Comment thread tests/level_1_5/test_three_first.py


@pytest.mark.xfail(reason='Incorrect work of function')
def test__is_subscription_if_expense_occurs_in_same_month(expense, history):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 предлагаю название с поведением: test__is_subscription__no_subscription_when_expense_occurs_in_same_month



@pytest.mark.xfail(reason='Incorrect work of function')
def test__is_subscription_if_expense_occurs_in_same_month(expense, history):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

history как соотносится с созданной внутри нашего теста expense_updated - неясно.
либо не хватает корректного названия у фикстуры, либо сама фикстура недостаточно универсальна, хотя и имеет неконкретизированное название. Либо она вообще не нужна и список фикстур можно создать прямо в тесте.

Условно:

# тут можем не задавать явно spent_in='Megafon' так как нам не важно, 
# мегафон ли это, нам важно только чтобы были одинаковые. 
# Такая же история с датами - но мы не имеем пока такой удобной фикстуры
prev_expense = make_expenses(spent_at=datetime(2023, 6, 1))  
history = [prev_expense]
expense = make_expenses(
    # можно заодно использовать значение предыдущего - сразу понятно, 
    # что в тесте важно, чтобы они были одинаковы
    spent_in=prev_expense.spent_in, 

    # при наличии удобной фикстуры с датами тоже 
    # можно было придумать что-то похожее
    spent_at=datetime(2023, 6, 10), 
) 
...

Comment thread tests/level_1_7/test_three_is_subscription.py
)
assert is_subscription(expense_updated, history) == False

def test__is_subscription_if_expense_occurs_less_than_3_times(expense:list[Expense], history:list[list[Expense]])->bool:
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/level_1_7/test_three_is_subscription.py
@Beloded1 Beloded1 merged commit d3eb782 into main Jun 13, 2023
@Beloded1 Beloded1 deleted the feature/do_next_stage_of_tests branch June 13, 2023 15:33
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