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

This plugin should not enable itself automatically #6

Open
mgorny opened this issue Jul 15, 2018 · 5 comments
Open

This plugin should not enable itself automatically #6

mgorny opened this issue Jul 15, 2018 · 5 comments

Comments

@mgorny
Copy link

mgorny commented Jul 15, 2018

Apparently installing pytest-relaxed causes the 'relaxed' rules to start applying automatically to all projects. This is causing huge breakage for Gentoo. Two example packages affected by this are hpack and pyftpdlib.

Could you please make the plugin disable new behavior by default, and require explicitly enabling it via command-line, like most of pytest plugins seem to do?

@bitprophet
Copy link
Owner

I wish I'd been cognizant of this when I first wrote it. Changing this now will be backwards incompatible, but I'm probably still the biggest user of this (in my other projects) so yea I'll look into fixing this & putting out a major release version at some point 😐

@koobs
Copy link

koobs commented Jun 24, 2019

Another example: pytest-xdist also affected, when pytest-relaxed is installed.

We either need this (all pytest plugins, actually) disabled by default, and/or a command line method in pytest to deterministically disable all plugins that aren't otherwise explicitly enabled by the test suite being run

@sanscore
Copy link

I wish I'd been cognizant of this when I first wrote it. Changing this now will be backwards incompatible, but I'm probably still the biggest user of this (in my other projects) so yea I'll look into fixing this & putting out a major release version at some point 😐

👋 You could add a --relax argument with:

def pytest_addoption(parser):
    group = parser.getgroup("pytest-relaxed")

    group.addoption('--relax',
                    action="store_true",
                    help='Enable pytest-relaxed')

https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_addoption

Then, to solve the backwards incompatibility problems, you would need to add documentation for users. Either, they add --relaxed on command line, or they add it into pytest.ini (etc.) under addopts.

[pytest]
addopts =
  --relaxed

https://docs.pytest.org/en/latest/reference.html#configuration-options

In your other projects, I would suggest the latter.

@sanscore
Copy link

sanscore commented Jun 24, 2019

Oh, and check for relaxed in pytest_configure:

@pytest.mark.trylast # So we can be sure builtin terminalreporter exists
def pytest_configure(config):
# TODO: we _may_ sometime want to do the isatty/slaveinput/etc checks that
# pytest-sugar does?
builtin = config.pluginmanager.getplugin("terminalreporter")
# Pass the configured, instantiated builtin terminal reporter to our
# instance so it can refer to e.g. the builtin reporter's configuration
ours = RelaxedReporter(builtin)
# Unregister the builtin first so only our output appears
config.pluginmanager.unregister(builtin)
config.pluginmanager.register(ours, "terminalreporter")

def pytest_conifgure(config):
    if (config.getoption('collectonly')
            or config.getoption('markers')
            or config.getoption('showfixtures')):
        pass
    elif not config.getoption('relaxed'):
        return
    ...

Edit: Added condition for collectonly, etc.

@anarcat
Copy link

anarcat commented Apr 1, 2022

sounds like this is just waiting for a PR, anyone up for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants