How can i invoke the CLI programmatically to run it in debug mode and step through the code?

Sometimes it is helpful to run a Great Expectations CLI command programmatically in order to run in debug mode and step through the code. This is relevant especially when you consider contributing an improvement or a bug fix, or just want to understand deeper how it works.

How can this be done?

Great Expectations CLI uses click - a module for building Python CLIs.

Click provides CliRunner in its testing submodule that can be used to run a CLI command programmatically. Below is an example of running the equivalent of “great_expectations suite scaffold mynewsuitename” command programmatically. Notice how you can also provide the answers to interactive prompts.

from click.testing import CliRunner
from great_expectations.cli import cli

target_directory = “the path to the directory with my great_expectations.yml” config file

runner = CliRunner(mix_stderr=False)

result = runner.invoke(
[“suite”, “scaffold”, “mynewsuitename”, “-d”, target_directory],
input=“1\nselect * from my_table limit 1000”,

1 Like