Add a New "Addopts" by Default in Pytest Plugin?

I want to disable capture by default in a pytest plugin I'm working on. This can be done using an "ini" file normally as below:

[pytest]
addopts = -s

In the pytest docs they discuss "addini", and this works for other values I've tried but not addopts.

An alternative way to approach is to override the argument directly like so:

def pytest_addoption(parser):
    parser.addoption(
        "--capture",
        dest="capture",
        help="Capture the output",
        default='no'
    )

...but this complains that there is an argument conflict with the existing capture argument.

Is there some other better practice for default values of addopts that I haven't thought of?

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article