robotframeworkguides icon indicating copy to clipboard operation
robotframeworkguides copied to clipboard

Docs > PreRunModifier > Copy and Modify Tests > Better use deepcopy()?

Open Christian390 opened this issue 1 year ago • 0 comments

Hello,

today was the first time I did create a pre-run-modifier. I started with a code example from https://docs.robotframework.org/docs/extending_robot_framework/listeners_prerun_api/prerunmodifier#copy-and-modify-tests

There a copy of the test gets done with copy(). I did that and found that if I change the setup, the setup was changed for the original test case and the copy. The same with the tags: I did add a tag to the copied test case but both test cases had the tag.

The reason is that copy() only does a shallow copy. After replacing copy() by deepcopy() everything went as expected: I was able to change the copy without changing the original.

So I suggest that you change in this line of your code example test_case = suite.tests.append(test.copy()) from copy() to deepcopy(). Thanks.

Christian390 avatar Nov 20 '23 15:11 Christian390