簡體   English   中英

如何在“ pytest”框架的夾具中的“拆卸”中使用測試結果

[英]How to use test result in “teardown” in fixtures 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