pytest-dev / pytest-dev/pytest-django
Upgrading to pytest-django 3.9 breaks test
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
When upgrading to pytest-django 3.9.0 one of my tests breaks.
@pytest.mark.django_db
@patch("ntnui.utils.gsuite.GSuite.unsubscribe_from_singular_mailing_list")
@patch("ntnui.utils.gsuite.GSuite.unsubscribe_from_board_mailing_list")
@patch("ntnui.utils.gsuite.GSuite.unsubscribe_from_group_mailing_list")
@pytest.mark.parametrize(
("membership_type", "leave_group_list", "leave_board_list", "leave_singular_list"),
[
(MembershipType.member, True, False, False),
(MembershipType.board_member, True, True, False),
(MembershipType.leader, True, True, True),
],
)
def test_unsubscribe_from_mailing_lists_member(
mock_unsubscribe_from_group_mailing_list,
mock_unsubscribe_from_board_mailing_list,
mock_unsubscribe_from_singular_mailing_list,
membership_type,
leave_group_list,
leave_board_list,
leave_singular_list,
user,
):
"""Test that members are unsubscribed from appropriate mailing lists when leaving a group."""
membership = MembershipFactory(type=membership_type, member=user)
membership.delete_membership()
assert mock_unsubscribe_from_group_mailing_list.called == leave_group_list
assert mock_unsubscribe_from_board_mailing_list.called == leave_board_list
assert mock_unsubscribe_from_singular_mailing_list.called == leave_singular_list
As you can see above, the test utilizes both mocking and parametrization. It seems like pytest-django 3.9 has some issues with the mocks. Furthermore, the ordering of the tests impacts the results. When running the test suit, this tests fails. When running the test suite once more, with the --failed-first option the test does not break.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the parametrized test for MembershipFactory and delete_membership using the mocked ntnui.utils.gsuite methods, first in the full test suite and then with --failed-first. Compare pytest-django 3.9 behavior and test ordering, and consider the issue done when the test passes consistently in both runs without weakening its assertions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100