Skip to content

Conversation

@ZohebShaikh
Copy link
Contributor

closes #262

The issue where running a single test in the VSCode debugger would trigger other tests was due to a known bug in pytest (pytest issue #7409).

This workaround is no longer necessary because VSCode's Python debugger (vscode-python-debugger) depends on debugpy, where the root cause was fixed in commit 1 and commit 2, as referenced in debugpy issue #275.

Therefore, the workaround can be safely removed. Simply ensure you're using the latest version of the VSCode Python Debugger currently (2025.8.0).More info on the extension: VSCode Python Debugger

@ZohebShaikh
Copy link
Contributor Author

I recommend testing this change in your local setup before merging, just to be safe.
I've verified it both inside the devcontainer and outside, and everything works as expected.

I couldn't delete the conftest.py file because the tests expect it to be present, so I had to leave an empty file in its place.

@ZohebShaikh ZohebShaikh requested review from DiamondJoseph, GDYendell, callumforrester and coretl and removed request for callumforrester May 9, 2025 15:12
@GDYendell
Copy link
Contributor

GDYendell commented May 13, 2025

running a single test in the VSCode debugger would trigger other tests

I have experienced this recently, but the code being removed here is not a workaround for that problem. It is to make the debugger stop on exceptions rather than pytest just swallowing them and this has existed for a while before I started seeing this behaviour. Are you sure these things are related?

@ZohebShaikh
Copy link
Contributor Author

I'm fairly confident these issues are related—if you take a look at this Stack Overflow answer, it uses exactly the same approach as in the copier template.

The comment there also references pytest issue #7409, which in turn depends on debugpy issue #275. Both of these have since been resolved, so simply updating the Python extension in VS Code should address the underlying problem.

Have you had a chance to try removing this workaround and testing it with the latest debugger?

@ZohebShaikh
Copy link
Contributor Author

ZohebShaikh commented May 13, 2025

I have tested this on ophyd-async it was showing the same bug and it is resolved if we apply this fix...

I checked in dodal ..it is working because PYTEST_RAISE is not set ..ie. making this workaround dead code...

I have tested this in blueapi and python-copier-template both are working with this fix

@GDYendell
Copy link
Contributor

GDYendell commented May 13, 2025

OK I think I see what you mean. If an exception is raised in a test then it is caught, but it also runs all of the other tests for some reason. It did not do this when this was first added.

If I take out the pytest hooks then it doesn't run all of the other tests, but it also doesn't stop on the exception. It seems like enabling "User uncaught exceptions" in vscode gives the same behaviour without needing to add the pytest hooks - is that right?

@ZohebShaikh
Copy link
Contributor Author

OK I think I see what you mean. If an exception is raised in a test then it is caught, but it also runs all of the other tests for some reason. It did not do this when this was first added.

Yes, this was broken recently.

If I take out the pytest hooks then it doesn't run all of the other tests, but it also doesn't stop on the exception. It seems like enabling "User uncaught exceptions" in vscode gives the same behaviour without needing to add the pytest hooks - is that right?

Yes..This is correct ...If "User uncaught exceptions" enabled by default is a requirement I can try using some workaround in conftest...but I think it will be quite hacky and might break quite often

@GDYendell
Copy link
Contributor

That's fine - it doesn't need to be on by default, that doesn't seem like it would be possible. This is more something that should go in the developer guide.

@ZohebShaikh ZohebShaikh merged commit 78cabc2 into main May 13, 2025
12 checks passed
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

Successfully merging this pull request may close these issues.

Debugging a unit test in vscode also triggers all other tests

3 participants