gotcha / ipdb

Integration of IPython pdb
BSD 3-Clause "New" or "Revised" License
1.85k stars 146 forks source link

set_trace doesn't stop in the right place #282

Open novalic opened 1 month ago

novalic commented 1 month ago

Having an issue in several different scenarios. I will describe one here.

I'm running some tests with pytest, and in this case I'm using a pydantic function, the code is:

    def test_something(self, expected_response):
        self.some_mock.return_value = httpx.Response(200, json=expected_response)

        result = some_function({}, {})

        assert result.model_dump() == expected_response
        import ipdb; ipdb.set_trace()

this test belongs to a test class, there is a mock definition, and expected_response is a pytest fixture that returns a dictionary.

when i run this, i come here:

    321             else:
    322                 copied.__dict__.update(update)
    323             copied.__pydantic_fields_set__.update(update.keys())
    324         return copied
    325
--> 326     def model_dump(
    327         self,
    328         *,
    329         mode: Literal['json', 'python'] | str = 'python',
    330         include: IncEx = None,

ipdb>

but if i comment the line assert result.model_dump() == expected_reponse things work fine:

     19
     20     def test_something(self, expected_response):
     21         self.some_mock.return_value = httpx.Response(200, json=expected_response)
     22
     23         result = some_function({}, {})
---> 24         import ipdb; ipdb.set_trace()
     25
     26
     27         #assert result.model_dump() == expected_response

this has happened a lot to me lately in different scenarios.