Skip to content

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

@rompe

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.

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