Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot debug test case in VS Code: Found duplicate in "env": PATH

I am using VS Code for developing in Python. I have been able to debug single test cases from the test module, which is very practical. Since recently, it no longer works. After a short waiting time, a dialog pops up: "Invalid message: Found duplicate in "env": PATH." with the buttons "Open launch.json" and "Cancel". Opening launch.json does not help, since I don't manipulate PATH there. I also did not edit PATH recently (and the message seems to point not to a wrong value in PATH, but to PATH being set multiple times).

I tried to see the duplicate PATH myself, but failed: Both echo ${env:PATH} at the console and os.environ in Python will only give a single PATH variable - as already implied by the used data structure.

I tried applying this SO answer. It does neither relate directly to VS Code, nor to duplicate PATH variables, but to duplicates in PATH, but it was the closest I found on here. It didn't work.

like image 764
Jann Poppinga Avatar asked Jul 14 '26 22:07

Jann Poppinga


2 Answers

I had this issue when trying to debug a test function (pytest) The solution that worked for me was to ensure I had created a debug unit test in my launch.json file as recommended here.

{
  "name": "Python: Debug Tests",
  "type": "debugpy",
  "request": "launch",
  "program": "${file}",
  "purpose": ["debug-test"],
  "console": "integratedTerminal",
  "justMyCode": false
}
like image 193
Matt Brown Avatar answered Jul 17 '26 17:07

Matt Brown


You can install different versions of the Python plugin (to whom it may concern: if this works unsatisfactorily, it may be because you have multiple instances of VS Code running). You will note:

  1. 2023.4.1 is the latest known stable version that works
  2. 2023.6.0 does not work
  3. v2023.7.11011538 (latest) works

It seems it's an issue in the latest stable version the VS Code team have solved in the meanwhile.

like image 21
Jann Poppinga Avatar answered Jul 17 '26 17:07

Jann Poppinga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!