-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
ValueError: no option named 'verbose' - during assertion eval, when Terminal plugin is disabled #9422
Comments
I still don't understand this issue, but I run into it from time to time in different environments. I'm using this workaround to manually force the from pathlib import Path
from _pytest.config import PytestPluginManager, Config, default_plugins
def run_pytest_cli(args, plugins):
# The majority of this function is copied from Pytest internals
pluginmanager = PytestPluginManager()
config = Config(
pluginmanager,
invocation_params=Config.InvocationParams(
args=args,
plugins=plugins,
dir=Path.cwd(),
),
)
# Here is the patch I've added to Pytest's source code to get around
# https://github.com/pytest-dev/pytest/issues/9422
config.option.verbose = True
pluginmanager.consider_preparse(args, exclude_only=True)
for default_plugin in default_plugins:
pluginmanager.import_plugin(default_plugin)
pluginmanager = config.pluginmanager
for plugin in plugins:
pluginmanager.register(plugin)
config = pluginmanager.hook.pytest_cmdline_parse(
pluginmanager=pluginmanager, args=args
)
exit_code = config.hook.pytest_cmdline_main(config=config)
return exit_code
# e.g.
if __name__ == "__main__":
failure_collector_plugin = FailureCollectorPlugin()
exit_code = run_pytest_cli(
args=["-p", "no:terminal"],
plugins=[failure_collector_plugin],
) |
Replication of the internals is a last resort i strongly recommend against using That being said, the use of the option should be changed However it should also be noted that disabling built in plugins is potentially dangerous I recommend taking a look at how xdist and sugar manage things |
I'm also running into this and have used a hack to get around the verbose problems, but in recent versions the assertion rewriter plugin has been failing if the terminal plugin is disabled. I wonder if the thing to do is to add a way to disable all output from the terminal reporter. The use case for this is when tests are run in a subprocess launched by an IDE or other tool and test success / failure is not reported through terminal output. |
The simple fix would be to add a default to the Would somebody like to give this a try? |
Hello @nicoddemus , |
Hi @ka28kumar, that's great to hear. No need for permission to get started, feel free to fork the project, and submit a PR (even if incomplete). |
Hi @nicoddemus , |
I believe its a good idea to unify all options of the built-in plugins so disabling plugins won't break CLI args and option expectations for the built-in plugins |
What do you mean, add the default to the verbose definition? Note that's already there: pytest/src/_pytest/terminal.py Lines 135 to 142 in 9446f02
The problem is actually that with
Interesting idea, for some builtin plugins this seems like a good option, not sure the same is true for every builtin plugin (for example |
Instead of calling `Config.option.verbose`, call the new `Config.get_verbosity` function to determine the verbosity level. This enables pytest to run correctly with the terminal plugin disabled. Fix #9422 (cherry picked from commit 72c682f) Co-authored-by: GTowers1 <[email protected]>
Execute
pytest
without the terminal plugin, i.e.pytest -p no:terminal -s
, when the test contains an assertion failure, for example:An exception is issued:
(https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/util.py#L161)
Additional reference to
config.option.verbose
: https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/truncate.py#L29The
verbose
parameter is set alongside with the Terminal plugin (https://github.com/pytest-dev/pytest/blob/main/src/_pytest/terminal.py#L144), but apparently is used by the assertion utils as well.Possible solution, moving
verbosity
setting from terminal pytest adoption to runner pytest_adoption , since the verbosity setting affects modules outside the terminal outputOur specific use case: Disable Terminal Plugin and forward results using dedicated logger. We achieve it by implementing the following:
Then we execute pytest with terminal plugin disabled. The problem occurs upon assertion failures and currently our workaround is setting
config.option.verbose
during the thepytest_configure
on our end.The text was updated successfully, but these errors were encountered: