Код: Выделить всё
import pytest
from dataclasses import dataclass
from typing import Dict
@dataclass
class OutputsToCheck:
a: int
b: int
expected: Dict[str, OutputsToCheck] = {
"test_1": OutputsToCheck(a=1, b=2),
"test_2": OutputsToCheck(a=3, b=4),
}
actual: Dict[str, OutputsToCheck] = {
"test_1": OutputsToCheck(a=1, b=2),
"test_2": OutputsToCheck(a=3, b=4),
}
Я пробовал вот что:
Код: Выделить всё
@pytest.fixture
def test_names():
return ["test_1", "test_2"]
@pytest.fixture
def expected_outputs():
return expected
@pytest.fixture
def actual_outputs():
return actual
@pytest.fixture
def make_test(expected_outputs, actual_outputs):
def test(test_name: str):
expected = expected_outputs[test_name]
actual = actual_outputs[test_name]
assert expected == actual
return test
@pytest.fixture
def make_tests(make_test, test_names):
output = {}
for name in test_names:
output[name] = make_test(name)
return output
def test(make_tests, test_names):
for name in test_names:
make_tests[name]
Есть ли способ добиться этого? Большое спасибо.
Подробнее здесь: https://stackoverflow.com/questions/785 ... test-names