Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have a way to force session scope teardown #1738

Closed
kalidasya opened this issue Jul 18, 2016 · 5 comments
Closed

Have a way to force session scope teardown #1738

kalidasya opened this issue Jul 18, 2016 · 5 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@kalidasya
Copy link

Hi,

I have a session scope fixture what provisions vms in openstack. Sometimes something else during the setup goes wrong, or there is keyboard interruption or jenkins job is terminated (probably similar to keyboard interrupt) in these cases the teardown is not executed and the vms remain in openstack. It would be nice if there can be a way to force the execution of the teardown.

@RonnyPfannschmidt RonnyPfannschmidt added the type: question general question, might be closed after 2 weeks of inactivity label Jul 19, 2016
@kalidasya
Copy link
Author

any update on this?

@nicoddemus
Copy link
Member

Hi @kalidasya, thanks for the ping on this.

There's nothing in pytest per-se, but you can take advantage of the fact that the finally block on a yield fixture will be guaranteed to be executed by Python:

import pytest

@pytest.fixture
def vm():
    try:
        raise ValueError
        yield 1
    finally:
        print('teardown')


def test(vm):
    pass
 pytest foo.py -q
E
=================================== ERRORS ====================================
___________________________ ERROR at setup of test ____________________________

    @pytest.fixture
    def vm():
        try:
>           raise ValueError
E           ValueError

foo.py:6: ValueError
---------------------------- Captured stdout setup ----------------------------
teardown
1 error in 0.03 seconds

@kalidasya
Copy link
Author

@nicoddemus thanks for the tip, I will try it out

@nicoddemus
Copy link
Member

No worries. Please let us know if it worked so we can close the issue.

@nicoddemus
Copy link
Member

Closing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants