Skip to content

Support different options for discovering and running tests with pytest #15148

Closed as not planned

Description

@rompe

I would like to use additional pytest options when running tests, but not when discovering tests.

Scenario

  1. I want to generate coverage data on every test run, so I have this in my settings.json:
    "python.testing.pytestArgs": [
        "src/unittests",
        "--cov=.",
        "--cov-report=xml:coverage.xml",
        "-vvv"
    ],
  1. But I don't want to generate coverage when debugging a test, so I disable it in my launch.json:
        {
            "name": "Debug Tests",
            "type": "python",
            "request": "test",
            "console": "integratedTerminal",
            "env": {"PYTEST_ADDOPTS": "--no-cov"},
            "justMyCode": false
        }
  1. I also don't want coverage data when tests are discovered because discovery is way faster without these options. This seems to be impossible at the moment.

What I need

I think I need either a possibility to inject the --no-cov option somewhere around

pytestargs.insert(0, "--collect-only")
or I need a possibility to just add the coverage options for non-debug test runs only.

Activity

  1. karthiknadig commented on Jan 14, 2021

    @karthiknadig
    Member

    Thank you for the suggestion! We have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 👍 votes the opening comment gets to help us make our decision.

  2. added
    needs spikeLabel for issues that need investigation before they can be worked on.
    and removed on Mar 10, 2021
  3. eleanorjboyd commented on Jul 26, 2023

    @eleanorjboyd
    Member

    same as #21255, closing this to move all discussion to that issue. Thanks!

  4. removed
    needs spikeLabel for issues that need investigation before they can be worked on.
    on Jul 26, 2023
  5. eleanorjboyd commented on Aug 18, 2023

    @eleanorjboyd
    Member

    I created a proposal with a solution for this problem, would love your input on the above issue! #21845

  6. locked as resolved and limited conversation to collaborators on Sep 18, 2023
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions