From f05becdf21c16c1cdc7ed522186448a917ad5240 Mon Sep 17 00:00:00 2001 From: Caio Ariede Date: Tue, 17 Sep 2024 16:38:58 -0300 Subject: [PATCH] fix import pytest later --- src/pytest_xflaky/add_decorator.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pytest_xflaky/add_decorator.py b/src/pytest_xflaky/add_decorator.py index accb85e..bdc7994 100644 --- a/src/pytest_xflaky/add_decorator.py +++ b/src/pytest_xflaky/add_decorator.py @@ -59,11 +59,6 @@ def traverse(node): else: return None - # add import pytest - if not is_pytest_imported: - import_statement = "import pytest\n" - source_code = import_statement + source_code - # skip if decorator already added if not any(d.startswith(b"@pytest.mark.xfail") for d in decorators): # Add the decorator before the function definition @@ -75,6 +70,11 @@ def traverse(node): + source_code[function_start_byte:] ) + # add import pytest + if not is_pytest_imported: + import_statement = "import pytest\n" + source_code = import_statement + source_code + with open(path, "w") as fp: fp.write(source_code)