pytest-dev / pyfakefs

Provides a fake file system that mocks the Python file system modules.
https://pytest-pyfakefs.readthedocs.io
Apache License 2.0
651 stars 91 forks source link

Using pyfakefs breaks vscode's debugger #1083

Open Aran-Fey opened 4 weeks ago

Aran-Fey commented 4 weeks ago

Using pyfakefs leads to a variety of issues with vscode's debugger, like breakpoints not working and duplicate file tabs being opened. I made a bug report here, but the folks at debugpy have decided it's not their responsibility to fix it. Can you guys take care of it?

Aran-Fey commented 4 weeks ago

This may only be an issue if PatchMode.AUTO is used, now that I think about it.

mrbean-bremen commented 4 weeks ago

Yeah, PatchMode.AUTO may have unwanted side effects and probably won't play nice with a debugger, as that relies on loading code on a low level. If this indeed only happens if patching open_code, there is probably not much we can do with reasonable effort. I don't think I want to go down that rabbit hole...

mrbean-bremen commented 3 weeks ago

@Aran-Fey - can you confirm that this only happens with PatchMode.AUTO?

Aran-Fey commented 3 weeks ago

Actually, nope. A duplicate tab is opened regardless of the PatchMode, and the breakpoints continue to sometimes be ignored without any apparent reason.

mrbean-bremen commented 3 weeks ago

Ok, thanks. I'm not using VSCode (I use PyCharm), so it may take a while to understand this. Do you have a way to reproduce this with some minimal example?

Aran-Fey commented 3 weeks ago

This seems to do it:

import typing

def test_demo(fs):
    typing.get_type_hints(int)
  1. Set a breakpoint at typing.get_type_hints(int) -> breakpoint is hit, duplicate file tab is opened
  2. Set a breakpoint inside of get_type_hints -> breakpoint is ignored
  3. Remove fs fixture: Both issues go away
mrbean-bremen commented 3 weeks ago

Thanks, I will give it a try!

mrbean-bremen commented 3 weeks ago

You are working with the current pyfakefs version (5.7.1), right?

mrbean-bremen commented 3 weeks ago

Ah, and which Python version are you using?

Aran-Fey commented 3 weeks ago

Correction: Only the duplicate tab issue goes away. Having some trouble reproducing the breakpoint issue. If I replace typing with a custom-made python module, the breakpoint is hit as expected. Maybe breakpoints don't work in the stdlib or something, or maybe it's just the bug being janky again. Really not sure.

I'm using pyfakefs 5.7.1 and cpython 3.10.13.

mrbean-bremen commented 3 weeks ago

So far, I have not been able to get sensible behavior even in tests without pyfakefs - I guess I have to better understand the workflow in VSCode first... Will have another go over the weekend.

mrbean-bremen commented 3 weeks ago

Ok, I persuaded VSCode to work for me, and I can reproduce the duplicate tab behavior now (not the ignored breakpoint so far). At the moment, I have no idea where to even look, so no promises...