ipdb icon indicating copy to clipboard operation
ipdb copied to clipboard

set_trace doesn't stop in the right place

Open novalic opened this issue 1 year ago • 1 comments

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.

novalic avatar Aug 06 '24 15:08 novalic

Interesting! I wonder if this is maybe related to the fact that PyTest is rewriting the AST nodes of the code to make assert robust. Seems like it could be a bug in PyTest, but one would have to investigate this further to see it in practice. Does the same problem occurrs if you use plain old pdb instead of ipdb? If so, then I would say this is a bug/issue with pytest itself, not ipdb (and then could be reported in their repository).

disconnect3d avatar Nov 13 '24 15:11 disconnect3d