首页 > 解决方案 > 邮箱仅在最后一个灯具时有效

问题描述

如果我像这样使用邮箱设备,它可以工作:

def test_send_invoices_via_mail_page(user_client, invoice, mailoutbox):
    url = reverse(send_invoices_via_mail_page)
    response = user_client.get(url)
    assert response.status_code == 200
    log = LogOfInvoiceMail.objects.get(invoice=invoice)
    assert log.success, log.exception
    assert log.invoice == invoice
    assert log.exception == ''
    assert len(mailoutbox) == 1, mailoutbox

但是,如果我这样使用它,它会失败:

    def test_send_invoices_via_mail_page(mailoutbox, user_client, invoice):

错误:

>       assert len(mailoutbox) == 1, mailoutbox
E       AssertionError: []
E       assert 0 == 1

为什么参数的顺序在这里很重要?

我 100% 确定mail.send_mail()在这两种情况下都会调用它,因为我测试了十次(用十种不同的方式)。

标签: pythondjangopytestpytest-django

解决方案


推荐阅读