1

I'm trying to use a Python testing framework via VSCode and think I've managed to get it almost working.

The current symptoms are that for the testing framework's modules:

  1. Go-to definition, peek and related functionality works
  2. pylint throws unresolved import errors

Other standard/pip-installed modules work fine.

What I have done is:

  1. Created a Python venv and configured VSCode to use it as my interpreter
  2. Set up the Python venv's activate script to update PYTHONPATH and GIT_REPO (a requirement of the framework)
  3. Added the following to .vscode/settings.json:
    "python.pythonPath": "/path/to/my/venv/bin/python",
    "python.testing.pytestEnabled": true,
    "python.testing.nosetestsEnabled": false,
    "python.testing.unittestEnabled": false,
    "python.envFile": "${workspaceFolder}/.env",
    "python.autoComplete.extraPaths": [
        "/path/to/the/framework/lib"
    ],

I got the python.autoComplete.extraPaths thing from this question and it was the step that got go-to definition and similar functionality working.

  1. Added the following to .env in the workspace folder:
    GIT_REPO=/path/to/the/framework
    PYTHONPATH=$GIT_REPO/lib
Kyle_S-C
  • 1,107
  • 1
  • 14
  • 31
  • So is the problem pylint flags things as not existing when they do? And is it select packages or all packages? And if it's select packages is it only the ones that would be found via your PYTHONPATH manipulations? – Brett Cannon Apr 01 '20 at 00:29
  • Exactly. It's only packages imported from `/path/to/the/framework/lib`, which I've added via the path manipulations you mentioned. I've expanded my question to hopefully be clearer. – Kyle_S-C Apr 01 '20 at 12:21
  • 1
    If you set your PYTHONPATH manually in the terminal and run the command that the extension runs on your behalf (can be found in the Output panel in the Python channel), does Pylint also complain there? If it does then it's a Pylint issue. If it doesn't then it's an issue with the extension and please file a bug at https://github.com/microsoft/vscode-python. – Brett Cannon Apr 01 '20 at 22:29
  • Thanks Brett! It looks like the issue is that the Python extension invokes Pylint using the venv's Python binary, but without the PYTHONPATH changes. I'll look for an issue at the extension's tracker and raise one if it's not there. If you want to post this as an answer, I'm happy to accept it and close this question. – Kyle_S-C Apr 02 '20 at 11:09
  • Further to this, it looks like it might be: https://github.com/microsoft/vscode-python/issues/9185 – Kyle_S-C Apr 02 '20 at 12:18

0 Answers0