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

Testing - Test View for Python with multi-root workspace #17041

Closed
3 tasks done
karthiknadig opened this issue Aug 19, 2021 · 6 comments
Closed
3 tasks done

Testing - Test View for Python with multi-root workspace #17041

karthiknadig opened this issue Aug 19, 2021 · 6 comments
Labels
testplan-item Test plan item/assignments for upcoming release
Milestone

Comments

@karthiknadig
Copy link
Member

karthiknadig commented Aug 19, 2021

Refs: #15750

Complexity: 3

Create Issue


Requirements

  1. Install python extension from here: https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix
  2. Make sure you have "python.experiments.optInto": ["All"], in your user settings. If you did not have it, add it and reload.

Testing

  1. Open either this project https://github.com/karthiknadig/multiroot_pytest_sample or create a project layout similar to that.
  2. Create a virtual environment in the repo directory and install pytest.
    1. Navigate to the repo directory in the terminal.
    2. Then use following commands to create virtual envs
      1. For windows, you can use this command py -3 -m venv .venv
      2. For mac/linux you can use the command python3 -m venv .venv
        Note: For linux users you may not have venv available out of the box. Please install python3-venv via apt.
    3. Activate the virtual environment:
      1. For windows : run the activate binary .\.venv\Scripts\activate
      2. For linux/mac (bash): run source ./.venv/bin/activate .
        Note: If you use other terminal shells there are scripts under Scripts or bin directory that should work for your preferred shell.
    4. Once activated you should see the name of the env in the prompt. Run the following command to install pytest: python -m pip install pytest
  3. Activate the python extension and select the virtual environment that you just created. Depending on where you create the virtual environment it may or may not show up in the quick pick. But you can always browse to it and select it.
  4. If you created your own files, then configure each project root for testing using the python: configure test command. Otherwise you should see the tests in the test view.
  5. Run the tests, add more files or test and see the Test UI update accordingly.
@karthiknadig karthiknadig added the testplan-item Test plan item/assignments for upcoming release label Aug 19, 2021
@karthiknadig karthiknadig added this to the August 2021 milestone Aug 19, 2021
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Aug 19, 2021
@karthiknadig karthiknadig removed the triage-needed Needs assignment to the proper sub-team label Aug 19, 2021
@sandy081
Copy link
Member

It worked as expected when I opened the root project multiroot_pytest_sample directly.
But did not work when opening included folders as a multi-root workspace. I followed the steps as mentioned and the testing view could not discover the tests

image

Here is the output from Python channel

> /usr/bin/python3 ~/work/testing/extension-dir/ms-python.python-2021.9.1144093763-dev/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/work/multiroot_pytest_sample/testfolder1 -s --cache-clear .
cwd: ~/work/multiroot_pytest_sample/testfolder1
> /usr/bin/python3 ~/work/testing/extension-dir/ms-python.python-2021.9.1144093763-dev/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/work/multiroot_pytest_sample/testfolder1 -s --cache-clear .
cwd: ~/work/multiroot_pytest_sample/testfolder1
Error 2021-08-24 11:40:06: Error discovering pytest tests:
 [r [Error]: Traceback (most recent call last):
  File "/Users/sandy081/work/testing/extension-dir/ms-python.python-2021.9.1144093763-dev/pythonFiles/testing_tools/run_adapter.py", line 17, in <module>
    from testing_tools.adapter.__main__ import parse_args, main
  File "/Users/sandy081/work/testing/extension-dir/ms-python.python-2021.9.1144093763-dev/pythonFiles/testing_tools/adapter/__main__.py", line 9, in <module>
    from . import pytest, report
  File "/Users/sandy081/work/testing/extension-dir/ms-python.python-2021.9.1144093763-dev/pythonFiles/testing_tools/adapter/pytest/__init__.py", line 7, in <module>
    from ._discovery import discover
  File "/Users/sandy081/work/testing/extension-dir/ms-python.python-2021.9.1144093763-dev/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 8, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'

	at ChildProcess.<anonymous> (/Users/sandy081/work/testing/extension-dir/ms-python.python-2021.9.1144093763-dev/out/client/extension.js:9:380127)
	at Object.onceWrapper (events.js:422:26)
	at ChildProcess.emit (events.js:315:20)
	at maybeClose (internal/child_process.js:1048:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)]

Please let me know if this is to test only root project or multi-root workspace?

@karthiknadig
Copy link
Member Author

When you open the multiroot_pytest.code-workspace you have to reselect the python. Here it may have picked the global python for you which if you followed the steps will not have (should not have) pytest installed. Hence the error.

@sandy081
Copy link
Member

Ok. How can I reselect the python and which version shall I have to pick in this case? Also is this in the scope of this test plan item?

@karthiknadig
Copy link
Member Author

karthiknadig commented Aug 24, 2021

@sandy081 That is not in the scope of this testing plan item. You can skip that.

You can re-select that python by running Python: Select interpreter command

@roblourens
Copy link
Member

Had some issues with the interpreter, should it be able to discover my virtualenv automatically? I had to put in the path manually. Then it seemed like the status bar item still said "Select Python Interpreter" and I had to do it a second time. But everything worked find after that point.

@roblourens roblourens removed their assignment Aug 26, 2021
@karthiknadig
Copy link
Member Author

@roblourens that is a know issue #16170, #16613

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
testplan-item Test plan item/assignments for upcoming release
Projects
None yet
Development

No branches or pull requests

4 participants