Как мне сообщить mypy, что кроме() выполнит тест pytest?Python

Программы на Python
Anonymous
Как мне сообщить mypy, что кроме() выполнит тест pytest?

Сообщение Anonymous »

Следующий код работает, но мне показалось, что мне не нужно его писать:

Код: Выделить всё

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.

Подробнее здесь: https://stackoverflow.com/questions/790 ... ytest-test

Вернуться в «Python»