Skip to content

Run Test and Debug Test have different PYTHONPATHs #4674

@bfrizb

Description

@bfrizb

Environment data

  • VS Code version: 1.32.0
  • Extension version (available under the Extensions sidebar): 2019.2.5558
  • OS and version: macOS Mojave 10.14.3
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: pytest==4.3.0

Expected behaviour

Run Test and Debug Test should execute from the same directory.

Actual behaviour

Run Test and Debug Test execute from different directories.
In my case, this means that all my python unit tests pass when I use Run Test, but I encounter ModuleNotFoundError using Debug Test.

It is unclear how to change the execution directories for Debug Test, relative to the ${workspaceFolder}, or if this is even possible.

screen shot 2019-03-07 at 2 16 37 pm

^ Notice in the screenshot above that the sys.path is different for Run Test vs Debug Test.

Asides:

  • I have essentially nothing in my Global settings.json file.
  • I've reproduced this issue on Two different macOS systems.

Steps to reproduce:

  1. git clone my demo/example github project (minimum code/files): https://github.com/bfrizb/demo_repo AND git checkout the vscode-python/issues/4674 branch.
  2. Open demo_repo in VSCode
  3. Try Run Test and Debug Test to observe the difference in behavior. Here is a video demonstrating the problem.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

For Run Test

============================= test session starts ==============================
platform darwin -- Python 3.7.0, pytest-4.3.0, py-1.8.0, pluggy-0.9.0
rootdir: /Users/bfrisbie/Downloads/test_repo/solution/src/python, inifile:
collected 1 item

tests/myfile_test.py F                                                   [100%]

=================================== FAILURES ===================================
___________________________________ test_add ___________________________________

    def test_add():
    	print(sys.path)
>   	assert False
E    assert False

tests/myfile_test.py:7: AssertionError
----------------------------- Captured stdout call -----------------------------
['/Users/bfrisbie/Downloads/test_repo/solution/src/python', '/Users/bfrisbie/Downloads/test_repo/solution/src/python', '/Users/bfrisbie/Downloads/test_repo/solution/src/python/src', '/Users/bfrisbie/Downloads/test_repo/solution/src/python/test', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/bfrisbie/Library/Python/3.7/lib/python/site-packages', '/usr/local/lib/python3.7/site-packages']
- generated xml file: /var/folders/l8/518s_8n51cj0lhp_5yjc55sm0000gp/T/tmp-29170sIk8mMwTxmB4.xml -
=========================== 1 failed in 0.04 seconds ===========================

For Debug Test:

============================= test session starts ==============================
platform darwin -- Python 3.7.0, pytest-4.3.0, py-1.8.0, pluggy-0.9.0
rootdir: /Users/bfrisbie/Downloads/test_repo/solution/src/python, inifile:
collected 1 item

tests/myfile_test.py F                                                   [100%]

=================================== FAILURES ===================================
___________________________________ test_add ___________________________________

    def test_add():
    	print(sys.path)
>   	assert False
E    assert False

tests/myfile_test.py:7: AssertionError
----------------------------- Captured stdout call -----------------------------
['/Users/bfrisbie/Downloads/test_repo/solution/src/python', '/Users/bfrisbie/Downloads/test_repo/solution/src/python', '/Users/bfrisbie/Downloads/test_repo/solution/src/python/src', '/Users/bfrisbie/Downloads/test_repo/solution/src/python/test', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/bfrisbie/Library/Python/3.7/lib/python/site-packages', '/usr/local/lib/python3.7/site-packages']
- generated xml file: /var/folders/l8/518s_8n51cj0lhp_5yjc55sm0000gp/T/tmp-29170sIk8mMwTxmB4.xml -
=========================== 1 failed in 0.04 seconds ===========================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions