pythonvisual-studio-codepytestvscode-debugger

VSCode shows duplicate tests in Python


I don't know if this due to a recent update, but I am seeing my Python tests appear twice and when I am in test debug mode it runs twice as well. How can I fix this? I just created an empty project and I am running into the same issue.

Steps to reproduce:

  1. python -m venv .venv (create virtualenv)

  2. source ./.venv/bin/activate (activate virtualenv)

  3. pip install pytest==8.3.3

  4. On VSCode select Python interpreter to be the virtualenv one.

  5. mkdir server server/tests

  6. Basic tests file

    # server/tests/test_storage.py
    import pytest
    
    class TestStorage:
        def test(self):
            pass
    
  7. Settings.json (I tried different variations with the directory)

    {
      "python.testing.pytestArgs": [
        "tests"
      ],
      "python.testing.unittestEnabled": false,
      "python.testing.pytestEnabled": true
    }
    

Screenshot of test module Screenshot 2 enter image description here

VSCode Version: 1.94.0 (Universal)


Solution

  • It turns out this was due to having both Python and Python Test Explorer for Visual Studio Code extensions enabled, both of them have test functionality. Disabling the latter fixed the issue.