Я пытался инкапсулировать их в класс и иметь только декоратор параметризации в классе
Я придумал код, похожий на этот
Код: Выделить всё
import pytest
def foo(A, B):
return A + B
def bar(A, B):
return A - B
@pytest.mark.parametrize("A,B,foo_output,bar_output", [
(1,2,3,-1),
(6,3,9,3),
...
])
class TestClass:
def test_foo(self, A, B, foo_output):
assert foo(A, B) == foo_output
def test_bar(self, A, B, bar_output):
assert bar(A, B) == bar_output
Код: Выделить всё
ERROR test/test_foo_bar.py::TestClass - Failed: In test_foo: function uses no argument 'bar_output'
Код: Выделить всё
ERROR test/test_foo_bar.py::TestClass - Failed: In test_bar: function uses no argument 'foo_output'
Я исправил это, создав в классе приспособление, принимающее эти аргументы в качестве приемника, но опять же, не уверен, что это лучший подход к проблеме
Код: Выделить всё
class TestClass:
@pytest.fixture(autouse=True)
def _ignore_args(self, foo_output, bar_output):
pass
...
Подробнее здесь: https://stackoverflow.com/questions/791 ... arametrize
Мобильная версия