You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When using pytest with multiple python projects inside the workspaceFolder, you cannot configure pytest to only run one project's test suite without breaking the abilty to run a single test method. #2454
When using a workspace with multiple python projects, you cannot configure pytest in a way that allows you to run tests with only one of the projects without breaking something else about the testing process.
The directory structure is like so:
projectIWantToTest
codeIWant
myOtherProject
codeIDontWant
Environment data
VS Code version: 1.26.1
Extension version (available under the Extensions sidebar): 2018.7.1
OS and version: Windows 10 1803
Python version (& distribution if applicable, e.g. Anaconda): 3.5.3
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
Relevant/affected Python packages and their versions: pytest (using 3.5.0)
Actual behavior
Option 1 - pytest arguments configured as [".", "--ignore=myOtherProject"]
Run/debug all tests - works fine
Run/debug a specific test - Causes all tests to be run.
Option 2 - pytest arguments configured as ["projectIWantToTest"]
Run/debug all tests - Works fine
Run/debug a specific test - Does not work. Returns an error saying that the test cannot be found (This seems to be due to pytest changing the path of the tests from projectIWantToTest/codeIWant/tests.. to codeIWant/tests..)
I have tried this with the python.unitTest.cwd config variable and it seems to do nothing, or at least does nothing with test discovery.
Expected behavior
Option 1 - Both running all tests and running a specific test works.
Option 2 - Either configuring the python.unitTest.cwd variable works with discovery and fixes this problem OR deal with pytest removing the absolute paths OR don't break discovery when --ignore is one of the arguments for pytest (or suggest valid workaround with pytest arguments)
I could also suggest another option that simply allows running all tests in a directory rather than all tests, a specific test file or a specific test method, which is a function i feel this extension has been missing for a long time (especially for people who came from PyCharm.)
Steps to reproduce:
Have two python projects with tests in the same workspace. Attempt to configure pytest to run and discover the tests of only one project. For all options i have tried this breaks the ability to run or debug a single test.
Note: Sorry about the super long title, it's quite a specific bug.
changed the title [-]When using pytest with multiple python projects inside the workspaceFolder, you cannot configure pytest to only run one project's test suite without breaking[/-][+]When using pytest with multiple python projects inside the workspaceFolder, you cannot configure pytest to only run one project's test suite without breaking the abilty to run a single test.[/+]on Aug 28, 2018
changed the title [-]When using pytest with multiple python projects inside the workspaceFolder, you cannot configure pytest to only run one project's test suite without breaking the abilty to run a single test.[/-][+]When using pytest with multiple python projects inside the workspaceFolder, you cannot configure pytest to only run one project's test suite without breaking the abilty to run a single test method.[/+]on Aug 28, 2018
I can verify that with issue2454.zip running all tests works but running a single test actually runs all tests plus the individual test (i.e. says 3 tests ran instead of 2).
I am also seeing this but with a single python project. Attempting to run a single test runs all tests. I'm using pytest 3.6.1, python 2.7, and VSCode 1.28.
It looks like the problem had to do with using addopts in setup.cfg. Overriding the config file in .vscode/settings.json like this fixed the issue:
Original issue is fixed by using multi-root workspaces, so closing it.
If anyone finds a problem related to this with single projects, please open a new issue.
Activity
[-]When using pytest with multiple python projects inside the workspaceFolder, you cannot configure pytest to only run one project's test suite without breaking[/-][+]When using pytest with multiple python projects inside the workspaceFolder, you cannot configure pytest to only run one project's test suite without breaking the abilty to run a single test.[/+][-]When using pytest with multiple python projects inside the workspaceFolder, you cannot configure pytest to only run one project's test suite without breaking the abilty to run a single test.[/-][+]When using pytest with multiple python projects inside the workspaceFolder, you cannot configure pytest to only run one project's test suite without breaking the abilty to run a single test method.[/+]brettcannon commentedon Aug 29, 2018
I can't reproduce. Can you try something like pytest 3.6 (we are working on a code lens bug with pytest 3.7 or else I would suggest that)?
jakegt1 commentedon Aug 30, 2018
I'll go make a git repo quickly to reproduce it, sorry about the poor explanation!
jakegt1 commentedon Aug 30, 2018
Brett Cannon (@brettcannon)
https://github.com/jakegt1/vscode-python-pytest-bug
jakegt1 commentedon Aug 30, 2018
Work around is to simply use multi-root workspaces (which probably makes more sense), but i'll leave this up to let you decide what to do with it.
brettcannon commentedon Sep 7, 2018
I'll verify this.
brettcannon commentedon Sep 24, 2018
I can verify that with issue2454.zip running all tests works but running a single test actually runs all tests plus the individual test (i.e. says 3 tests ran instead of 2).
southwood commentedon Oct 11, 2018
I am also seeing this but with a single python project. Attempting to run a single test runs all tests. I'm using pytest 3.6.1, python 2.7, and VSCode 1.28.
It looks like the problem had to do with using
addoptsin setup.cfg. Overriding the config file in .vscode/settings.json like this fixed the issue:luabud commentedon Sep 11, 2019
Original issue is fixed by using multi-root workspaces, so closing it.
If anyone finds a problem related to this with single projects, please open a new issue.