0

I felt this is a beginner question but somehow I am stuck and don't know how to search this up. If anyone can point to me the issue that will be great. So I am doing a pytest for the code, I have the following dictionary set in the beginning

dict_a = {"a": "", "b": "", "c":""}

class TestInfo:
    def test1(self):
        dict_a["a"] = "abc"
        assert dict_a["a"] = "abc"
        assert dict_a["b"] = ""
        assert dict_a["c"] = ""

    def test2(self):
        dict_a["b"] = "def"
        assert dict_a["a"] = ""
        assert dict_a["b"] = "def"
        assert dict_a["c"] = ""

Now test2 fail because dict_a["a"] still is "abc", I tried to have dict_a reset by the following:

dict_a_original = {"a": "", "b": "", "c":""}

class TestInfo:
    def test1(self):
        dict_a = dict_a_original
        dict_a["a"] = "abc"
        assert dict_a["a"] = "abc"
        assert dict_a["b"] = ""
        assert dict_a["c"] = ""

    def test2(self):
        dict_a = dict_a_original
        dict_a["b"] = "def"
        assert dict_a["a"] = ""
        assert dict_a["b"] = "def"
        assert dict_a["c"] = ""

but then dict_a_original also update when dict_a update, which make this useless. I knew this was a thing but I can't recall how to resolve this, can someone help me on this?

Thanks

Norman Kuo
  • 143
  • 7

0 Answers0