From 65fab7f1c54cbe4a88158976e93d835cae9b7bac Mon Sep 17 00:00:00 2001 From: Kirill Sosnovskikh Date: Tue, 20 Aug 2024 18:05:34 +0300 Subject: [PATCH] Fix fixture lookup in `pytest_generate_tests` Signed-off-by: Kirill Sosnovskikh --- README.md | 2 +- src/allure_validator/collect.py | 34 ++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 6924395..c98cb59 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Additionally, `allure-validator` can be added to pre-commit hooks: # .pre-commit-config.yaml repos: - repo: https://git.frostfs.info/TrueCloudLab/allure-validator - rev: 1.0.0 + rev: latest hooks: - id: allure-validator args: ["pytest_tests/"] diff --git a/src/allure_validator/collect.py b/src/allure_validator/collect.py index e0343bd..f077432 100644 --- a/src/allure_validator/collect.py +++ b/src/allure_validator/collect.py @@ -133,21 +133,25 @@ def fixtures(ast_fixtures: list[ast.FunctionDef], ast_hooks: list[ast.FunctionDe for ast_hook in ast_hooks: path = getattr(ast_hook, ATTR_PATH) - for node in ast_hook.body: - if isinstance(node, ast.Expr): - if parse.decorator(node.value) == PYTEST_METAFUNC_PARAMETRIZE: - fixture_names = parse.param_names(node.value.args[0]) - for name in fixture_names: - # Dynamic fake fixture - fixture = Fixture( - name, - path, - node.lineno, - node.col_offset, - args=[], - params=["parametrized"], - ) - fixtures[fixture] = fixture + for node in ast.walk(ast_hook): + if not isinstance(node, ast.Expr): + continue + + if parse.decorator(node.value) != PYTEST_METAFUNC_PARAMETRIZE: + continue + + fixture_names = parse.param_names(node.value.args[0]) + for name in fixture_names: + # Dynamic fake fixture + fixture = Fixture( + name, + path, + node.lineno, + node.col_offset, + args=[], + params=["parametrized"], + ) + fixtures[fixture] = fixture for fixture in fixtures.values(): for arg in fixture.args: