2014-11-20 2 views
0

의 Carthesian 제품은 다음있는 TestSuite 내가 두기구 datashapePytest는 : 의존 비품

import pytest 

@pytest.fixture(params=1, 2, 3) 
def shape(request): 
    return request.param 


@pytest.fixture 
def data(shape): 
    return shape 


def test_resize(data, shape): 
    pass 

을 상상해보십시오. data은 조명기 shape에 따라 다르며 가능한 값마다 생성됩니다. 그러나 test_resize에서 나는 datashape의 가능한 모든 조합을 통해 테스트 할 :

  • 1, 1
  • 1, 2
  • 1, 3
  • 2, 1

등 위의 구현을 통해 카티 시안 제품을 확장하지는 않습니다.

  • 1, 1
  • 2,
  • 3 2,

3 py.test하는 모든 가능한 조합으로 설비를 확장 할 수있는 방법이 있나요?

답변

2
하여 출력 보듯

, shape 매개 변수화하지만 data 따라서 만 shape 조명기의 각 인스턴스에 대한 data 정체의 하나 인스턴스있을 것이다 아니다. 또한 data을 매개 변수화합니다. 그런 다음 여전히 data 조명기를 가지고있는 경우 shape에 따라 원하는 제품을 얻을 수 있습니다.

import pytest 

fixture_params = (1, 2, 3) 

@pytest.fixture(params=fixture_params) 
def shape(request): 
    return request.param 

@pytest.fixture(params=fixture_params) 
def data(request, shape): 
    print(request.param) 
    return request.param 

def test_resize(data, shape): 
    print(data, shape) 
    assert 0 and 'assert to show prints'