setup_cleanup
вызывает тестовую функцию, но она все еще является функцией. Исключение, возникшее на любом шаге, предотвратит возбуждение остальной части.
Обходным путем будет использование try finally
. Это позволит запустить тест и демонтаж без проглатывания исключения
@pytest.fixture(scope="class", autouse=True)
def setup_cleanup(self, request):
try:
print('Setup')
raise Exception("Setup Exception")
yield
finally:
print('Teardown')
def test_example_test(self):
print('Test')
За исключением
Setup
Teardown
test setup failed
self = <ExampleTest.TestSomething object at 0x045E6230>
request = <SubRequest 'setup_cleanup' for <Function test_something>>
@pytest.fixture(scope="class", autouse=True)
def setup_cleanup(self, request):
print()
try:
print('Setup')
> raise Exception("Setup Exception")
E Exception: Setup Exception
И без
Setup
.Test
Teardown