В моем наборе тестирования у меня есть много кода, подобного следующему: < /p>
# file test/test_procedural.py
from test.helper import check_evaluation
@pytest.mark.parametrize(
("str_expr", "msgs", "assert_fail_msg"),
[
(
"Abort[a, b]",
["Abort called with 2 arguments; 0 arguments are expected."],
"Abort argument error call",
),
(
"Catch[a, b, c, d, e]",
["Catch called with 5 arguments; between 1 and 3 arguments are expected."],
"Catch argument error call",
),
# ...
],
)
def test_wrong_number_of_arguments(str_expr, msgs, assert_fail_msg):
check_evaluation(
str_expr,
str_expr,
to_string_expr=True,
to_string_expected=True,
hold_expected=True,
failure_message=assert_fail_msg,
expected_messages=msgs,
)
# file test/test_strings.py
from test.helper import check_evaluation
@pytest.mark.parametrize(
("str_expr", "msgs", "assert_fail_msg"),
[
(
"ToExpression[]",
(
"ToExpression called with 0 arguments; between 1 and 3 arguments are expected.",
),
"ToExpression argument error call",
),
],
)
def test_wrong_number_of_arguments(str_expr, msgs, assert_fail_msg):
check_evaluation(
str_expr,
str_expr,
to_string_expr=True,
to_string_expected=True,
hold_expected=True,
failure_message=assert_fail_msg,
expected_messages=msgs,
)
Вместо определения test_wrong_number_of_arguments много раз я хотел бы определить это oonge в helper и украшать это в каждом файле с помощью pytest.mark.paramatize .
Как я могу сделать это? Нанесите декоратор на импортируемую функцию?, но задача здесь - самоанализ Pytest. Когда я пытаюсь: < /p>
from test.helper import wrong_number_of_arguments
test_wrong_number_of_arguments = pytest.mark.parametrize(wrong_number_of_arguments,
("str_expr", "msgs", "assert_fail_msg"),
[
(
"ToExpression[]",
(
"ToExpression called with 0 arguments; between 1 and 3 arguments are expected.",
),
"ToExpression argument error call",
),
],
)
и запустить pytest , я получаю:
/tmp/3.13.7/lib/python3.13/site-packages/_pytest/mark/structures.py:391: PytestCollectionWarning: cannot collect 'test_wrong_number_of_arguments' because it is not a function.
def __call__(self, *args: object, **kwargs: object):
Подробнее здесь: https://stackoverflow.com/questions/797 ... n-imported
Как я могу прикрепить Python Decorator Factory @pytest.mark.paramerize к импортированной функции? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как я могу прикрепить Python Decorator @pytest.mark.paramerize к импортированной функции?
Anonymous » » в форуме Python - 0 Ответы
- 1 Просмотры
-
Последнее сообщение Anonymous
-