pytest-dev / pytest-dev/pytest
Allow plugins to cause a "command line usage error"
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
What's the problem this feature will solve?
I am trying to write a pytest plugin that has several command line flags. Some combinations of these flags are "illegal", for example in the sense that they contradict each other. However, I noticed that there seems to be no way to terminate the program with the standard "usage error" output as for example seen from argparse.
Describe the solution you'd like
There should be a method, for example named cmdline_error, for example at the Config class, that causes the usage error message "ERROR: usage: pytest [options] ..." to appear, followed by the termination of the program with the appropriate exit code.
Alternative Solutions
Currently, the way I achieve this is by accessing the error function of the underlying argparse parser via config._parser._getparser().error in the pytest_configure hook. But of course, accessing names starting with underscores is not generally a good idea.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Config class and the pytest_configure hook, then trace how config._parser._getparser().error currently produces argparse-style usage errors. Compare that path with pytest's plugin-facing APIs and define the public behavior requested: standard usage output followed by the appropriate exit code when a plugin reports an invalid flag combination.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100