pypyr.steps.assert permalink

stop pipeline execution if condition false permalink

Assert that something is True or equal to something else.

  - name: pypyr.steps.assert
    comment: evaluate as truthy
    in:
      assert:
        this: '{evaluateMe}'
  - name: pypyr.steps.assert
    comment: compare two complex types - list with nested dictionaries.
    in:
      assert:
        this: '{complexThing1}'
        equals: '{complexThing2}'

Uses these context keys:

  • assert
    • this
      • mandatory
        • If equals not specified, evaluates as a boolean.
    • equals
      • optional
        • If specified, compares this to equals

If assert['this'] evaluates to False raises error.

If you also specify assert['equals'], raises error if assert['this'] != assert['equals'].

The step raises an exception of type AssertionError if the assertion fails.

All inputs support string substitutions.

examples permalink

boolean permalink

assert: # continue pipeline
  this: True
assert: # stop pipeline
  this: False

substitutions permalink

interestingValue: True
assert:
  this: '{interestingValue}' # continue with pipeline

non-0 numbers evaluate to True permalink

assert:
  this: 1 # non-0 numbers assert to True. continue with pipeline

string equality permalink

assert:
  this: 'up the valleys wild'
  equals: 'down the valleys wild' # strings not equal. stop pipeline.

string equality with substitutions permalink

k1: 'down'
k2: 'down'
assert:
  this: '{k1} the valleys wild'
  equals: '{k2} the valleys wild' # substituted strings equal. continue pipeline.

number equality permalink

assert:
  this: 123.45
  equals: 0123.450 # numbers equal. continue with pipeline.

number equality with substitutions permalink

numberOne: 123.45
numberTwo: 678.9
assert:
  this: '{numberOne}'
  equals: '{numberTwo}' # substituted numbers not equal. Stop pipeline.

complex types permalink

complexOne:
  - thing1
  - k1: value1
    k2: value2
    k3:
      - sub list 1
      - sub list 2
complexTwo:
  - thing1
  - k1: value1
    k2: value2
    k3:
      - sub list 1
      - sub list 2
assert:
  this: '{complexOne}'
  equals: '{complexTwo}' # substituted types equal. Continue pipeline.

worked example permalink

See a worked example for assert.

see also

last updated on .