Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
chrimaho opened this issue May 22, 2023 · 2 comments · Fixed by #11036
Closed

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

chrimaho opened this issue May 22, 2023 · 2 comments · Fixed by #11036
Labels
topic: config related to config handling, argument parsing and config file type: enhancement new feature or API change, should be merged into features branch

Comments

@chrimaho
Copy link
Contributor

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.

@RonnyPfannschmidt
Copy link
Member

Personally I would prefer --config-file

It's a trivial change, would you be up for creating a pull request with the change and a test?

@RonnyPfannschmidt RonnyPfannschmidt added type: enhancement new feature or API change, should be merged into features branch topic: config related to config handling, argument parsing and config file labels May 23, 2023
@chrimaho
Copy link
Contributor Author

Challenge accepted 😉
Please give me a few days.
Thanks!

nicoddemus pushed a commit that referenced this issue May 26, 2023
Fixes #11031

Signed-off-by: Chris Mahoney <chrismahoey@hotmail.com>
Co-authored-by: Chris Mahoney <chrismahoey@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: config related to config handling, argument parsing and config file type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants