[TIP] py.test test status check at teardown

Baiju M baiju.m.mail at gmail.com
Thu Aug 9 08:48:29 PDT 2012


Hi,

I am using a funcarg with cached_setup with scope as 'function'.
At teardown, I want to check whether test is failed or not
and perform some action. Any pointers ?
Here is my sample code.

class Webdriver(object):
    def get_screenshot_as_base64(self):
        return "ScreenShot"
    def quit(self):
        pass

def _get_webdriver():
    return Webdriver()

def _release_webdriver(webdriver):
    # FIXME: How to check test is failed or not ?
    screenshot = webdriver.get_screenshot_as_base64()
    webdriver.quit()

def pytest_funcarg__resource(request):

    return request.cached_setup(
        setup=_get_webdriver,
        teardown=_release_webdriver,
        scope='function')

def test_hello_without_screenshot(resource):
    assert 1 == 1

def test_hello_with_screenshot(resource):
    assert 1 == 2

--
Baiju M



More information about the testing-in-python mailing list