Skip to content
Latchkey

Python "click.exceptions.UsageError" in CI

Click raises UsageError (and exits 2) when a command is invoked with a missing required option, an invalid value, or an unknown subcommand. The traceback names the specific problem.

What this error means

A Click-based CLI step fails with "Error: No such option: --foo", "Error: Missing option '--name'", or "Error: No such command 'bar'".

python
Error: No such option: --new-flag

Common causes

A missing required option or argument

The CI command omitted an option the command marks as required.

An option or subcommand that does not exist in this version

The installed package version does not define the flag or command being passed.

How to fix it

Match the invocation to the command definition

  1. Run the command with --help to see its real options and subcommands.
  2. Supply required options or add them to the @click.option decorators.
  3. Pin the package so the CLI surface is stable across runs.
Python
@click.command()
@click.option("--name", required=True)
def run(name):
    ...

How to prevent it

  • Pin the CLI package version in CI.
  • Keep CI invocations aligned with the command signature.
  • Use Click testing.CliRunner to cover the invocation in unit tests.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →