-
Notifications
You must be signed in to change notification settings - Fork 203
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
CLI: Fix results not being committed in verdi code delete
#5848
Conversation
@chrisjsewell the failure started after the changes to the I am not exactly sure why the changes are not being committed. When the command calls For now, to demonstrate a potential fix, I added the opening of a transaction in the |
Indeed, it appears |
The change that caused this fixed another problem related to the same code 😅 so I would prefer not to revert it. |
By default the `run_cli_command` fixture will run the provided command through the `CliRunner` utility provided by `click`. However, this suffers from a problem as the code pathway followed through the runner is not identical as when the command is actually called through the CLI. The reason is that in `click` commands do not have a reference to their parents, and so when a subcommand is invoked through the runner, only the code of the subcommand is executed. Any code that is part of its parents, such as parameter validation and callbacks are skipped. In addition, the runner is executed in the same interpreter as where the test suite is being run, whereas a command invoked through the actual CLI runs in a standalone interpreter. This may hide subtle bugs. Therefore, the `use_subprocess` argument is added, which is `False` by default, which when set to `True`, the command will not be called through the runner, but as an actual subprocess using `subprocess.run`. This guarantees that the tested pathway is identical to what an actual invocation through the command line would be. It is not enabled by default since running through a subprocess is slower and not always necessary.
The `verdi code delete` command would report that the `Code` was deleted but the changes were actually not committed. This went unnoticed since the test for it used the `click.CliRunner` which doesn't follow the exact same path as a real invocation on the command line. In particular, in this example the treatment of the session is different with it not being committed properly in the command line invocation pathway. The problem is shown by using `use_subprocess=True` when calling the command using the `run_cli_command` fixture, after which the test fails.
125930d
to
f2ea104
Compare
f2ea104
to
f6870cd
Compare
The bug introduced actually affects way more than just |
Fixes #5842
The
verdi code delete
command would report that theCode
was deletedbut the changes were actually not committed. This went unnoticed since
the test for it used the
click.CliRunner
which doesn't follow theexact same path as a real invocation on the command line. In particular,
in this example the treatment of the session is different with it not
being committed properly in the command line invocation pathway. The
problem is shown by using
use_subprocess=True
when calling the commandusing the
run_cli_command
fixture, after which the test fails.