简体   繁体   English

如何在“ pytest”框架的夹具中的“拆卸”中使用测试结果

[英]How to use test result in “teardown” in fixtures in “pytest” framework

I am trying to use test result or status in tear down of the fixture, but I am not able to find the code without using the keyword "yield".. in "pytest" framework. 我试图在拆卸夹具时使用测试结果或状态,但是如果在“ pytest”框架中不使用关键字“ yield” ..,就无法找到代码。

import pytest
import requests

@pytest.fixture
def update_result_todb(request):
    print('In update_result_toDB')
    def _fin():
        try:
            if(testPassed):  # looking for this
                print('Result updated to DB successfully')
            else:
                print('test failed')

        except:
           print ('exception raised')

    request.addfinalizer(_fin)
    return _fin

def test_failure(update_result_todb):
    print('test_failure')
    assert 1 == 0

def test_success(update_result_todb):
    print('test_success')
    assert 0 == 0

** **

import pytest
import requests
@pytest.fixture
def update_result_todb(request):
    print('In update_result_toDB')
    def _fin():
        try:
            if(request.node.rep_setup.passed):  # this works
                print('Result updated to DB successfully')
            else:
                print('test failed')
        except:
           print ('exception raised')
    request.addfinalizer(_fin)
    return _fin
def test_failure(update_result_todb):
    print('test_failure')
    assert 1 == 0
def test_success(update_result_todb):
    print('test_success')
    assert 0 == 0

** **

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM