Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeatedly prompts: Test framework pytest is not installed. Install? #2512

Closed
dazzag24 opened this issue Sep 6, 2018 · 16 comments
Closed

Repeatedly prompts: Test framework pytest is not installed. Install? #2512

dazzag24 opened this issue Sep 6, 2018 · 16 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@dazzag24
Copy link

dazzag24 commented Sep 6, 2018

Environment data

  • VS Code version:
    Version: 1.27.1
    Commit: 5944e81f3c46a3938a82c701f96d7a59b074cfdc
    Date: 2018-09-06T09:21:47.222Z
    Electron: 2.0.7
    Chrome: 61.0.3163.100
    Node.js: 8.9.3
    V8: 6.1.534.41
    Architecture: x64

  • Extension version (available under the Extensions sidebar): 2018.8.0

  • OS and version: Linux Ubuntu 16.04

  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.5.2

  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pipenv

  • Relevant/affected Python packages and their versions: XXX

Actual behavior

VSCode repeatedly asks: Test framework pytest is not installed. Install?

Yes is selected and it used pipenv install --dev pytest to install which succeeds.

Have said yes several times and yet it is still unable to find pytest.

Expected behavior

After installing pytest it should detect pytest and detect test folders.

Steps to reproduce:

  1. Instal vscode-python extension into folder that has pytests in "tests" folder.

Logs

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

No relevent logs can be seen from the extension.

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

XXX
@brettcannon brettcannon added bug Issue identified by VS Code Team member as probable bug area-testing info-needed Issue requires more information from poster labels Sep 6, 2018
@brettcannon
Copy link
Member

What is the output from the pipenv install --dev pytest commands that you are seeing being executed? And if you launch a Python terminal with Python: Create Terminal does python -c "import pytest" succeed?

@dazzag24
Copy link
Author

dazzag24 commented Sep 6, 2018

Could be related to this issue:
https://github.com/DonJayamanne/pythonVSCode/issues/307#issuecomment-338429353

Looking again for the logs I see in the "Python Test Logs" this:
Test Discovery failed:
Error: spawn /home/xxx/.virtualenvs/zzz-pKfsRWl3/bin/pytest ENOENT

but this file does exists:
$ ls -alF /home/xxx/.virtualenvs/zzz-pKfsRWl3/bin/pytest
-rwxrwxr-x 1 xxx xxx 251 Jun 5 19:48 /home/xxx/.virtualenvs/zzz-pKfsRWl3/bin/pytest*

@dazzag24
Copy link
Author

dazzag24 commented Sep 6, 2018

pipenv install pytest --dev
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project.
Installing pytest…
Looking in indexes: https://pypi.python.org/simple
Requirement already satisfied: pytest in /home/xxx/.virtualenvs/zzz-pKfsRWl3/lib/python3.5/site-packages (3.5.1)
Requirement already satisfied: more-itertools>=4.0.0 in /home/xxx/.virtualenvs/zzz-pKfsRWl3/lib/python3.5/site-packages (from pytest) (4.1.0)
Requirement already satisfied: setuptools in /home/xxx/.virtualenvs/zzz-pKfsRWl3/lib/python3.5/site-packages (from pytest)(39.2.0)
Requirement already satisfied: attrs>=17.4.0 in /home/xxx/.virtualenvs/zzz-pKfsRWl3/lib/python3.5/site-packages (from pytest) (18.1.0)
Requirement already satisfied: pluggy<0.7,>=0.5 in /home/xxx/.virtualenvs/zzz-pKfsRWl3/lib/python3.5/site-packages (from pytest) (0.6.0)
Requirement already satisfied: py>=1.5.0 in /home/xxx/.virtualenvs/zzz-pKfsRWl3/lib/python3.5/site-packages (from pytest) (1.5.3)
Requirement already satisfied: six>=1.10.0 in /home/xxx/.virtualenvs/zzz-pKfsRWl3/lib/python3.5/site-packages (from pytest) (1.11.0)

Adding pytest to Pipfile's [dev-packages]…
Installing dependencies from Pipfile.lock (11f8f8)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 58/58 — 00:00:21

@dazzag24
Copy link
Author

dazzag24 commented Sep 6, 2018

Running "python -c "import pytest" from the terminal in vscode does not cause an error

@mzjp2
Copy link

mzjp2 commented Sep 7, 2018

Got the exact same error, what fixed it for me was to create a VS Code workspace containing the folder and using "Open Workspace" instead of using "Open Folder" like I usually do.

@brettcannon brettcannon added needs verification and removed info-needed Issue requires more information from poster labels Sep 7, 2018
@brettcannon brettcannon self-assigned this Sep 7, 2018
@brettcannon
Copy link
Member

I'll try to verify this.

@dazzag24

This comment has been minimized.

@james-rose
Copy link

I had the same issue and got it fixed when I realized that my workspace contained a folder with unit tests from another project. I removed the folder from the workspace and then the error went away and it started working.

@brettcannon brettcannon added info-needed Issue requires more information from poster and removed needs verification labels Sep 20, 2018
@brettcannon
Copy link
Member

@dazzag24 I can't reproduce. Any chance you can provide a zip of some code that exhibits the problem? And when you try and run that pytest command that was triggering ENOENT does it run okay?

@owencjones
Copy link

I've had this issue too, took the following extra steps, but haven't succeeded yet:

  • Wrote a node script to spawn the same file that the plugin would - the script worked without ENOENT
  • Examined the plugin code trying to see why it's having an issue, nothing seems wrong yet

I'm currently working on the assumption that it's an issue with either a full system path, or spawning in the context of a virtual env (in my case a pipenv).

Will post further if I have any luck.

@brettcannon
Copy link
Member

@owencjones when you did the spawn() call with your own Node script did you set the shell environment on? If there's something environment-specific to make it work that would be a difference as we don't execute through the shell.

And thanks for trying to help!

@owencjones
Copy link

@brettcannon shell environment as in virtualenv/pipenv etc? No. I don't know of any reason that a childProcess.spawn call couldn't work for within one though. If I get chance, I'll try.

I found that, in my case, I was having some issues with another extension that I have to switch pipenv environments, so essentially the environment was being switched twice. In addition, my .profile script includes a switch on cwd. Removing this made the tests discoverable, and runnable, although I still have some bugs in other related areas.

That's my fix, but I think that it's going to differ between people - In my case, this helped:

  • Not running .profile hooks (in my case zsh, but I imagine the same true of bash, sh etc.)
  • Removing other Python and Test related extensions, and reintroducing them one by one to see if any clash.

Not an out and out fix, but a good approach to debugging these problems. We could do with finding the real cause of the failed spawn, which I think is because the spawn is working out an module to run, in src/client/unittests/common/runner.ts, but I'm supplying it with a the path to bin/pytest within the pipenv.

Could be that this issue can be avoided by giving the path to the module, not the bin file, and maybe rewording the setting to reflect this, or having 2 settings, one for the binary, and one for the module, either of which could be used.

I'd write this and put in a PR, but I've pretty much exhausted my time on this.

@brettcannon
Copy link
Member

@owencjones I was actually asking about the shell argument to spawn().

@owencjones
Copy link

owencjones commented Oct 19, 2018

@brettcannon Ah right, well no, I didn't supply any specific options. It's calling an absolute path though, so I don't think that should be the issue. Code below:

import  spawn from 'child_process'

const ls = spawn('/Users/owen/.local/share/virtualenvs/response-operations-ui-UKi5yJkT/bin/pytest');  // real, existing file

ls.stdout.on('data', (data) => console.log(`stdout: ${data}`));

ls.stderr.on('data', (data) => console.log(`stderr: ${data}`));

ls.on('close', (code) => console.log(`child process exited with code ${code}`));

It runs pytest fine and then exits with errorlevel 0.

somewhat irrelevant if you're not using spawn!

@DonJayamanne
Copy link

@owencjones

  • Can you try running the same script using <python> -m pytest (using the fully qualified path to your python environment)
  • Next, can you try adding the following setting in your workspace .vscode/settings.json file:
    "python.unitTest.pyTestPath": "/Users/owen/.local/share/virtualenvs/response-operations-ui-UKi5yJkT/bin/pytest"

Please let us know how both work out.

@brettcannon brettcannon added triage and removed area-testing bug Issue identified by VS Code Team member as probable bug labels Oct 24, 2018
@brettcannon
Copy link
Member

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

6 participants