Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add new gotcha #1158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
acampove opened this issue May 18, 2025 · 0 comments
Open

Add new gotcha #1158

acampove opened this issue May 18, 2025 · 0 comments

Comments

@acampove
Copy link

Hi,

While running tests on my code I was doing something like:

class Data:
    mylist = [1,2,3,4]


def test_function():
    local_list = Data.mylist
    local_list+=new_list

    # Do stuff with 

and there are multiple tests using mylist. This is going to modify the list instead of creating a new one, an unexpected behavior of +=. This will let one test talk to the tests happening later. The safer approach is:

class Data:
    mylist = [1,2,3,4]


def test_function():
    local_list =new_list + Data.mylist

    # Do stuff with 

here + will copy the list. Could you please add this case?

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant