2016-07-04 3 views
0

필자의 테스트 포인트는 web-app에 로그인하고, 테이블 항목을 만들고, 승인하고, 항목 상태를 확인하고, 제거하고, 로그 아웃하는 것이다. 따라서 공통 사전 조건/사후 조건이있는 유사한 테스트 케이스가 거의 없기 때문에 픽스처 (scope=function)를 만들기로 결정했습니다.pytest fixtures를 실행하는 시간을 줄이는 방법

@pytest.fixture 
def create_new_entry(): 
    # code for new entry creation using POST-request with python-requests(pre-condition) 

@pytest.fixture 
def login(): 
    # get to URL and complete authorization with Selenium 

@pytest.fixture 
def tear_down(request) 
    def logout_remove(): 
     # logout from web-app with Selenium. Remove entry from table using POST-request with python-requests (post-condition) 
    request.addfinalizer(logout_remove) 

def test_1(create_new_entry, login, tear_down): 
    # code to approve entry 
    assert # whether entry approved or not 

코드는 작동하지만, 어떤 이유로 테스트 실행을 위해 몇 분 동안 단지 (픽스처에서) 동일한 코드를 사용하는 경우보다 시간이 더 걸립니다 : (라인 수십 있기 때문에 거의 간체) 내 코드는 다음과 같습니다 직접 테스트 :

def test_1(): 
    # code for new entry creation using POST-request with python-requests(pre-condition) 
    # get to URL and complete authorization with Selenium 
    # code to approve entry 
    assert # whether entry approved or not 
    # logout from web-app with Selenium. Remove entry from table using POST-request with python-requests (post-condition) 

그래서 궁금하다 : 그것은 pytest 비품 실행하거나 시간을 줄일 수있는 방법이 너무 많은 시간을 필요로하는 것이 정상입니다?

+0

모든 테스트마다 조명기를 다시 만들어야합니까, 아니면 다른 테스트에서 동일한 객체를 한 번 만들 수 있습니까? 후자의 경우, 세션 또는 모듈 단위로 생성 될 조명기를 표시 할 수 있습니다 :'@ pytest.fixture (scope = 'session')'또는'@ pytest.fixture (scope = 'module')'. –

+0

예, 각 조명기는 테스트 당 한 번 적용해야합니다. 따라서 'scope ='function ''이 필요합니다 – Andersson

답변

0

테스트 코드가 어떻게 실행되고 있는지에 따라 달라 지므로 실제로 얼마나 많은 연산과 통합이 이루어지고 있는지를 알 수 있습니다. pytest는 mysql과 같은 실제 서비스 요청이없는 한 범위를 렌더링하는 데 시간이 많이 걸리지 않는다고 생각합니다.

요청 세션을 조롱하거나 vrc lib를 사용할 수 있습니다.

희망이 있습니다.

관련 문제