Как указать mypy, что except() отменяет тест pytest?
Следующий код работает, но мне кажется, что я не должен его писать:
def test_transaction(self, the_client):
[...]
transaction: Transaction = transactions.filter([...]).first()
# NOTE: this is stupid and unnecessary just to satisfy mypy.
# the next expect() will bail if this test is true,
# so this if statement is completely superfluous
if transaction is None:
raise AssertionError("missing transaction")
# I want to tell mypy this works like the above if statement
expect(transaction).not_to(be_none())
# if the if statement above isn't there, it tells me
# None | Transaction doesn't have the property "client"
expect(transaction.client).to(equal(the_client))
[...]
Есть ли более простой способ сделать это, который удовлетворит mypy? У меня 1000+ подобных тестов, и я не хочу добавлять еще 2000+ строк совершенно ненужного, бесполезного кода только для того, чтобы порадовать чертову программу проверки кода.
У меня установлены заглушки django и drf.