1
내가 시험이 같은 다른기구에 의존하는 pytest.fixture
과 스위트,이 사용 테스트 매개 변수화 : 일반 시험에 대한Pytest가 고정
@pytest.fixture
def params():
return {'foo': 'bar', 'baz': 1}
@pytest.fixture
def config():
return ['foo', 'bar', 'baz']
@pytest.client
def client(params, config):
return MockClient(params, config)
을, 난 그냥 client
에 전달하고 그것을 잘 작동합니다 :
그러나 매개 변수화 된 테스트의 경우 해당 픽스처를 사용하는 것은 정말 어색합니다. 모든 조명기 메소드를 직접 호출해야하는데, 이는 어느 정도 목적을 저지합니다. (params
과 config
조명기는 다른 곳에서 사용되므로 client
으로 붕괴시키고 싶지는 않습니다.
@pytest.mark.parametrize('thing,expected', [
(client(params(), config()).method_with_args(arg1, arg2), 100),
(client(params(), config()).method_with_args(arg2, arg4), 200),
])
def test_parameters(thing, expected):
assert thing == expected
이 클리너를 만드는 방법이 있습니까? 이 지저분한 코드가 반복적 인 유사한 테스트보다 낫지는 않습니다.