Skip to content

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

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-testingbugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions