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”,