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 pytest #17040

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

Testing - Test View for Python pytest #17040

karthiknadig opened this issue Aug 19, 2021 · 2 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. You will need python 3.6 or greater.
  2. Install python extension from here: https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix
  3. 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 an empty folder in VS Code.
  2. Add following pytest code:
import pytest


def test_passing():
    pass


@pytest.mark.parametrize(("x"), [[0], [1], [10]])
def test_parametrized_passing(x):
    pass


@pytest.mark.skip()
def test_skipping(x):
    pass


def test_failing():
    assert 0
  1. Be sure to name your file test_<name>.py.
  2. Create a virtual env in the project folder (we recommend this to avoid installing packages to your global environment). You can do this by running py -3 -m venv .venv (on windows), or python3 -m venv .venv (on linux/mac). Note: for nix/mac users you may have to install venv depending on your distribution.
  3. Once you have the virtual env, select it using the Python: select interpreter command or from the status bar.
  4. Now you have to configure tests using Python: configure tests... command from the command pallet, or go the test view and configure by using the test welcome view, or you can run tests to get a prompt to configure. Select pytest and follow the prompt.
  5. Depending on the scenario you may either get a prompt to install pytest or the extension will install pytest for you. If for some reason it does not install for you or get the prompt (file a bug). But do install it manually using this command from a activated terminal (see the .venv in the prompt indicated it is activated)
    image
  6. You should see the tests in the test view. Run the tests.
  7. Add your own test methods, or add another test file, the test UI should update accordingly.
@isidorn
Copy link

isidorn commented Aug 24, 2021

Works nice, good job 👏

@sandy081
Copy link
Member

@greazer A friendly reminder to test this Test Plan Item. If you are busy with other stuff please let me know so that I can ask someone else to test. Thanks.

@rzhao271 rzhao271 assigned rzhao271 and unassigned greazer and rzhao271 Aug 26, 2021
@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

6 participants