I am using py.test to write some tests and in my tests I utilize funcargs. These funcargs have their own setups and teardowns defined in the conftest.py like this:
conftest.py:
def pytest_funcarg__resource_name(request):
def setup():
# do setup
def teardown():
# do teardown
My problem is when someone uses CTRL+C to stop the test executions it leaves everything un-teardowned.
I know there is a hook pytest_keyboard_interrupt but I dont know what to do from there.
Sorry for the noobish question.
You don’t provide a full example so maybe i am missing something. But here is an example of how it can work, using the request.cached_setup() helper:
If you run this with “py.test” you get:
which shows that setup and teardown are called if a KeyboardInterrupt occurs during test execution.