forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Milestone
Description
Refs: #15750
- macOS @isidorn
- linux @connor4312
- windows @rzhao271
Complexity: 3
Requirements
- You will need python 3.6 or greater.
- Install python extension from here: https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix
- Make sure you have
"python.experiments.optInto": ["All"],in your user settings. If you did not have it, add it and reload.
Testing
- Open an empty folder in VS Code.
- Add following
pytestcode:
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- Be sure to name your file
test_<name>.py. - 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), orpython3 -m venv .venv(on linux/mac). Note: for nix/mac users you may have to installvenvdepending on your distribution. - Once you have the virtual env, select it using the
Python: select interpretercommand or from the status bar. - 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. Selectpytestand follow the prompt. - Depending on the scenario you may either get a prompt to install
pytestor the extension will installpytestfor 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)

- You should see the tests in the test view. Run the tests.
- Add your own test methods, or add another test file, the test UI should update accordingly.