Skip to content

Add additional flag CLI flag to the Ini Options: --config-file #11031

@chrimaho

Description

@chrimaho

Add additional flag CLI flag to the Ini Options: --config-file

What's the current situation?

The PyTest config currently has one config flag that can be used for loading config from a file: -c. As outlined here and here.

This means that if I wanted to run my pytest script from a pyproject.toml file, I'd need to run it like this:

pytest -c pyproject.toml

With the pyproject.toml file containing the following config:

[tool.pytest.ini_options]
addopts = "--verbose --cov=src --cov-report=term --cov-report=html:cov-report/html --cov-report=xml:cov-report/xml/cov-report.xml"
testpaths = [
    "src",
]

What's the problem this feature will solve?

The current solution works. However, for someone new to the team, who see this flag -c, they'd need to go digging through the documentation to try and find out what it means. Which may take some time.

Describe the solution you'd like

To streamline this process, I'd like to add an additional flag to the existing -c flag. This new flag should be a double-hyphen flag, and be either --config or --config-file.

That way, it is clear and unmistakable what this flag would be doing.

Therefore, in addition to running the command like this:

pytest -c pyproject.toml

This command should also work just the same if the command looked like this:

pytest --config-file pyproject.toml

Additional context

By way of context, other Python packages that also supply config in the pyproject.toml file also have the longer version of the flag in their CLI config.

For example:

  • MyPy uses the command: --config-file CONFIG_FILE. See here.
  • Black uses the command: --config FILE. See here.

It would be beneficial if PyTest could also implement a flag similar to Packages like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: configrelated to config handling, argument parsing and config filetype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions